Question 19.30

How can I invoke another program or command and trap its output?


Unix and some other systems provide a popen routine, 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


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback