Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

popen(3) [ultrix man page]

popen(3)						     Library Functions Manual							  popen(3)

Name
       popen, pclose - initiate I/O to/from a process

Syntax
       #include <stdio.h>

       FILE *popen(command, type)
       char *command, *type;

       pclose(stream)
       FILE *stream;

Description
       The arguments to are pointers to null-terminated strings containing respectively a shell command line and an I/O mode, either "r" for read-
       ing or "w" for writing.	It creates a pipe between the calling process and the command to be executed.  The  value  returned  is  a  stream
       pointer that can be used (as appropriate) to write to the standard input of the command or read from its standard output.

       A stream opened by should be closed by 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, and a type "w" as an output filter.

Diagnostics
       The routine returns a null pointer if files or processes cannot be created, or the shell cannot be accessed.

       The routine returns -1 if stream is not associated with a `popened' command.

Restrictions
       Buffered reading before opening an input filter may leave the standard input of that filter mispositioned.  Similar problems with an output
       filter may be forestalled by careful buffer flushing, for instance, with For further information, see

       The routine always calls and never calls

See Also
       sh(1), pipe(2), wait(2), system(3), fclose(3s), fopen(3s)

																	  popen(3)

Check Out this Related Man Page

popen(3S)																 popen(3S)

NAME
popen(), pclose() - initiate pipe I/O to/from a process SYNOPSIS
DESCRIPTION
creates a pipe between the calling program and a command to be executed by the POSIX shell, (see sh-posix(1)). The arguments to are pointers to null-terminated strings containing, respectively, a shell command line and an I/O mode, either for reading or for writing. returns a stream pointer such that one can write to the standard input of the command if the I/O mode is by writing to the file stream; and one can read from the standard output of the command if the I/O mode is by reading from the file stream. Because open files are shared, a type command can be used as an input filter and a type command as an output filter. If mode is other than or the result is undefined. A stream opened by should be closed by which waits for the associated process to terminate and returns the exit status of the command. However, if a call caused the termination status to be unavailable to then returns -1 with errno set to This can happen in one of the fol- lowing conditions: o If the signal handler for is set to o If the signal handler or another thread in the same process issues or call. APPLICATION USAGE
After a stream is associated with a pipe by the stream is byte-oriented (see orientation(5)). RETURN VALUE
Upon successful completion, returns a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it returns a NULL pointer if files or processes cannot be created and set errno to indicate the error. The success of the command execution can be checked by examining the return value of Upon successful return, returns the termination status of the command language interpreter. Otherwise, returns -1 if stream is not associ- ated with a command and set errno to indicate the error. ERRORS
The function fails if: The maximum number of file descriptors allowed are currently open. The function fails if: The status of the child process is not available. WARNINGS
If the original and processes concurrently read or write a common file, neither should use buffered I/O because the buffering will not work properly. Problems with an output filter can be forestalled by careful buffer flushing, e.g., with see fclose(3S). SEE ALSO
pipe(2), wait(2), fclose(3S), fopen(3S), system(3S), orientation(5), thread_safety(5). STANDARDS CONFORMANCE
popen(3S)
Man Page