Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.programmer Subject: Re: LOST in a PIPE Message-ID: <1991Feb25.174114.8830@athena.mit.edu> Date: 25 Feb 91 17:41:14 GMT References: <782@skipper.dfrf.nasa.gov> Sender: news@athena.mit.edu (News system) Distribution: usa Organization: Massachusetts Institute of Technology Lines: 29 Well, you can't use system() or popen(), because neither of them allow you to do what you want to to, i.e. read the stderr output of the tar process. In the former case, system(), it doesn't allow you to read any output at all. In the latter case, popen(), you can read stdout but not stderr, since stderr automatically goes to whatever the stderr of your process is. Ah, but wait, there's a trick! You can do this: 1. Create a pipe. 2. Fclose(stderr). 3. Fdopen() the write end of the pipe and assign the return value to stderr. At this point, you've got a pipe connected to stderr, and you can find out what goes into the pipe by reading from the read end of the pipe. Then, you can use popen() to start the tar process, and read from the FILE * returned by the popen, or from the read end of the pipe, as appropriate. Since output will be going to both at the same time, you might want to use select() or poll() to watch both at once and read from one of them was there is output available on it. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710 Brought to you by Super Global Mega Corp .com