Re: STDout
- Posted by jbrown1050 at hotpop.com Jan 17, 2003
- 364 views
On Fri, Jan 17, 2003 at 12:51:36PM +1100, Patrick.Barnes at transgrid.com.au wrote: > > In a command-line interface (DOS, not linux) adding "> filename" > to the end of your command redirects the output to a file instead. > > Is there any other places you can redirect it? Ideally, I'd like > a system() command that returns a string to the euphoria program. The redirection thing applies to Linux as well btw, jtlyk. There is like popen() for linux to do that sort of redirection you want, for DOS it can be emulated. I've included at the very bottom of this message some sample code, which works on ANY platform, that acts like system(), but returns the output. It merely redirects the output to a temp file, then reads the output from the file into a string, and then deletes the temp file, however. (To the best of my knowledge thats the only way to do it for DOS. Even the shell uses temporary files to simulate command line pipes iirc.) jbrown > > ======================= > Patrick Barnes > Information Systems Group > 201 Elizabeth St, Sydney > Patrick.Barnes at transgrid.com.au > Ext: 91-3583 > Ph:(02) 9284-3583 > Mob: 0410 751 044 > > > *********************************************************************** > > > *********************************************************************** > > > > TOPICA - Start your own email discussion group. FREE! ---the file --start comout.e -- command output -- emulates bash's `command` abilites. -- very convient -- slightly modified for use in DOS constant tempfile = "c:\\temp\\euout.tmp" --include fset.e --simplified file operations --start fset.e function readf(sequence name) sequence data integer h h = open(name, "r") if h = -1 then return "" end if data = "" while 1 do data &= getc(h) if data[length(data)] = -1 then data = data[1..length(data)-1] exit end if end while close(h) return data end function procedure writef(sequence name, sequence data) integer h h = open(name, "w") if h = -1 then return end if puts(h, data) close(h) end procedure function breadf(sequence name) sequence data integer h h = open(name, "rb") if h = -1 then return "" end if data = "" while 1 do data &= getc(h) if data[length(data)] = -1 then data = data[1..length(data)-1] exit end if end while close(h) return data end function procedure bwritef(sequence name, sequence data) integer h h = open(name, "wb") if h = -1 then return end if puts(h, data) close(h) end procedure global function fset(sequence name, sequence mode, object data) if not find(mode, {"wb", "rb", "w", "r"}) then return -1 end if if equal(mode, "r") then return readf(name) end if if equal(mode, "w") then writef(name, data) return 1 end if if equal(mode, "rb") then return breadf(name) end if if equal(mode, "wb") then bwritef(name, data) return 1 end if end function --end fset.e global function comout(sequence command) system(command&" > "&tempfile, 2) --run command return fset(tempfile, "r", 0) --return output in tempfile end function --end comout.e