Re: Reading program output from stdin
From: Ben Pfaff (blp_at_cs.stanford.edu)
Date: 03/31/04
- Next message: Poor Chap: "Opinions on resources, C99, FAQs on C"
- Previous message: Joona I Palaste: "Re: Help : pro*c"
- In reply to: mpearo: "Reading program output from stdin"
- Next in thread: James Deutsch: "Re: Reading program output from stdin"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 10:26:31 -0800
"mpearo" <mpearo@suffolk.lib.ny.us> writes:
> I have a program that calls ping. I would like to read the output back into
> the calling program for further action. Any ideas and/or help would be
> greatly appreciated.
If you'd read the FAQ, you would already have an answer.
19.30: How can I invoke another program or command and trap its output?
A: Unix and some other systems provide a popen() function, which
sets up a stdio stream on a pipe connected to the process
running a command, so that the output can be read (or the input
supplied). (Also, remember to call pclose().)
If you can't use popen(), you may be able to use system(), with
the output going to a file which you then open and read.
If you're using Unix and popen() isn't sufficient, you can learn
about pipe(), dup(), fork(), and exec().
(One thing that probably would *not* work, by the way, would be
to use freopen().)
References: PCS Sec. 11 p. 169.
-- "IMO, Perl is an excellent language to break your teeth on" --Micah Cowan
- Next message: Poor Chap: "Opinions on resources, C99, FAQs on C"
- Previous message: Joona I Palaste: "Re: Help : pro*c"
- In reply to: mpearo: "Reading program output from stdin"
- Next in thread: James Deutsch: "Re: Reading program output from stdin"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]