#include <stdio.h>
FILE *popen(command, type) char *command, *type;
pclose(stream) FILE *stream;
A stream opened by popen() should be closed by pclose(), which waits for the associated process to terminate and returns the exit status of the command.
Because open files are shared, a type r command may be used as an input filter, reading its standard input (which is also the standard output of the process doing the popen()) and providing filtered input on the stream, and a type w command may be used as an output filter, reading a stream of output written to the stream process doing the popen() and further filtering it and writing it to its standard output (which is also the standard input of the process doing the popen()).
popen() always calls sh.1 never csh.1
popen() returns a NULL pointer if the pipe or process cannot be created, or if it cannot allocate as much memory as it needs.
pclose() returns -1 if stream is not associated with a `popened' command.
If the original and `popened' processes concurrently read or write a common file, neither should use buffered I/O, because the buffering gets all mixed up. Similar problems with an output filter may be forestalled by careful buffer flushing, for instance, with fflush(); see fclose.3v
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97