Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
OSS Library Calls (n - r) popen(3)
NAME
popen - Initiates a pipe to a process
LIBRARY
G-series native OSS processes: /G/system/sysnn/zossesrl
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zossedll |
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/yossedll |
SYNOPSIS
#include <stdio.h>
FILE *popen(
const char *command,
const char *mode);
PARAMETERS
command Points to a null-terminated string containing a shell command line.
mode Points to a null-terminated string indicating an I/O mode. If the string pointed to
by mode is either r or w, then the following occurs. If the string pointed to by
mode is anything other than r or w, errno is set to [EINVAL] and a null string is
returned.
r When mode specifies r, the file descriptor STDOUT_FILENO
of the new child process is the writable end of the pipe. The
readable end of the pipe is the calling process’s file descriptor
(fileno(stream)), where stream is the stream pointer returned by
popen( ).
w When mode specifies w, the file descriptor STDIN_FILENO of
the new child process is the readable end of the pipe. The writ-
able end of the pipe is the calling process’s file descriptor
(fileno(stream)), where stream is the stream pointer returned by
popen( ).
Because open files are shared, a mode r command can be used as an input filter
and a mode w command as an output filter.
DESCRIPTION
The popen( ) function creates a pipe between the calling program and a shell command to be
executed, indicated by the command parameter, and then executes the command. popen( )
returns a pointer to a FILE structure for the stream. This stream can be either read from or writ-
ten to.
The popen( ) function invokes the fork( ) function to create a child process that in turn uses the
execl() function to run the sh shell, which interprets the shell command contained in the com-
mand parameter. The current process waits until the shell has finished, then returns the termina-
tion status of the shell.
A stream opened with the popen( ) function should be closed with the pclose( ) function.
After the popen( ) function is finished, the parent process and its child process can act indepen-
dently of each other.
527187-017 Hewlett-Packard Company 5−55