1. STDout

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.

=======================
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


***********************************************************************




***********************************************************************

new topic     » topic index » view message » categorize

2. Re: STDout

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

new topic     » goto parent     » topic index » view message » categorize

3. Re: STDout

On Fri, Jan 17, 2003 at 03:12:05PM +1100, Patrick.Barnes at transgrid.com.au
wrote:
> 
> Hmm... I think that would be too slow.
> 
> I have to ping 1300 names, and for each record what the IP address resolves
> too, and whether the ping a) succeeds b)times out or c) does not resolve the IP
> address
> 
> Any alternative to piping the ping output into a file, and reading it 1300
> times?
> 

Use >> instead of >, and read it in once, instead of 1300 times.

However, using real pipes would be better. (I know how to do this for Linux,
but not windows, sry.)

jbrown

> 
> -----Original Message-----
> From: jbrown1050 at hotpop.com [mailto:jbrown1050 at hotpop.com]
> Sent: Friday, 17 January 2003 13:53
> To: EUforum
> Subject: Re: STDout
> 
> 
> 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]
<snip>

> 
> 
-- 
 /"\  ASCII ribbon
 \ /  campain against
  X   HTML e-mail and
 /*\  news and unneeded MIME

new topic     » goto parent     » topic index » view message » categorize

4. Re: STDout

Actually, why not make it a DOS program instead of a Windows program?
That would get rid of the consoles.

-- 
 /"\  ASCII ribbon
 \ /  campain against
  X   HTML e-mail and
 /*\  news and unneeded MIME

new topic     » goto parent     » topic index » view message » categorize

5. Re: STDout

On Mon, Jan 20, 2003 at 10:40:51AM +1100, Patrick.Barnes at transgrid.com.au
wrote:
> 
> Oh, I see...
> 
> The main source of latency though is the time taken to do the pings... one at
> a time.
> 
> I'll just do it with '>', because of the very different formats that a ping
> output can take. I see, a '>>' appends to the file, rather than clearing it.
> 
> When I do a system() call, a dos box appears. When I do 1300 system calls,
> they pop up sequentially of the course of an hour or so. Now this is particularly
> irritating! Anyway to stop them appearing? There is nothing displayed in the
> dosboxes, because any output is redirected to a file.
> 

I don't do windows, so I have no idea.

But other ppl have solved this problem before, so search the mailing
list I suppose.

> -----Original Message-----
> From: 'jbrown1050 at hotpop.com' [mailto:jbrown1050 at hotpop.com]
> Sent: Monday, 20 January 2003 10:01
> To: Barnes Patrick
> Subject: Re: STDout
> 
> 
> On Mon, Jan 20, 2003 at 09:32:58AM +1100, Barnes Patrick wrote:
> > I don't get it.
> > 
> > command line example?
> 
> --start of example
> 
> constant ping_addr = {...} --put your addrs in there, or maybe read from a
> file.
> 
> constant datafile = "12345678.123"
> 
> procedure system_r(sequence s)
> 	system(s&" >> "&datafile, 2)
> end procedure
> 
> --ping them all at once.
> for i = 1 to length(ping_addr) do
> 	system_r("ping "&ping_addr[i])
> end for
> 
> integer h
> h = open(datafile, "r")
> --at this point, the output of all 1300 pings have been saved to file,
> --so you can read it all at once.
> 
> --end of example
> 
> Is that simple enough for you?
> 
> > 
> > -----Original Message-----
> > From: 'jbrown1050 at hotpop.com' [mailto:jbrown1050 at hotpop.com]
> > Sent: Monday, 20 January 2003 09:33
> > To: Barnes Patrick
> > Subject: Re: STDout
> > 
> > 
> > On Mon, Jan 20, 2003 at 08:54:50AM +1100, Barnes Patrick wrote:
> > > >>Use >> instead of >, and read it in once, instead of 1300 times.
> > > 
> > > I don't understand the use of >> as opposed to >. There are 1300 names to
> > > ping, and each time I need to get the text from that ping returned to the
> > > euphoria program.
> > 
> > Using '>>' lets you ping 1300 times, but read it in all at once.
> > 
> > That may not be signifcantly faster however, doing it in windows via pipes
> > (Elliott tells me CreatePipe(), DuplicateHandle(), and CreateProcess() is
> > the way to go, tho I know not the specifics) is the best method.
> > 
> > jbrown
> > 
> > > 
> > > -----Original Message-----
> > > From: jbrown1050 at hotpop.com [mailto:jbrown1050 at hotpop.com]
> > > Sent: Friday, 17 January 2003 15:49
> > > To: EUforum
> > > Subject: Re: STDout
> > > 
> > > 
> > > On Fri, Jan 17, 2003 at 03:12:05PM +1100, Patrick.Barnes at
> > > transgrid.com.au wrote:
> > > > 
> > > > Hmm... I think that would be too slow.
> > > > 
> > > > I have to ping 1300 names, and for each record what the IP address
> > > > resolves too, and whether the ping a) succeeds b)times out or c) does not resolve
> > > > the IP address
> > > > 
> > > > Any alternative to piping the ping output into a file, and reading it
> > > > 1300 times?
> > > > 
> > > 
> > > Use >> instead of >, and read it in once, instead of 1300 times.
> > > 
> > > However, using real pipes would be better. (I know how to do this for
> > > Linux,
> > > but not windows, sry.)
> > > 
> > > jbrown
> > > 
> > > > 
> > > > -----Original Message-----
> > > > From: jbrown1050 at hotpop.com [mailto:jbrown1050 at hotpop.com]
> > > > Sent: Friday, 17 January 2003 13:53
> > > > To: EUforum
> > > > Subject: Re: STDout
> > > > 
> > > > 
> > > > 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.
> > > > 
<snip>

> 
> 
-- 
 /"\  ASCII ribbon
 \ /  campain against
  X   HTML e-mail and
 /*\  news and unneeded MIME

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu