Open System Services Library Calls Reference Manual (G06.27+, H06.04+)
popen(3) OSS Library Calls Reference Manual
NAME
popen - Initiates a pipe to a process
LIBRARY
G-series native OSS processes: /G/system/sysnn/zossesrl
H-series OSS processes: /G/system/zdllnnn/zossedll
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.
Use From the Guardian Environment
If called from a Guardian process, a null pointer is returned and errno is set to [ENOTOSS].
5−30 Hewlett-Packard Company 527187-004