HP 3000 Manuals

popen [ MPE/iX Developer's Kit Reference Manual Volume I ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume I

popen 

Open a pipe to a command and execute the command. 

Syntax 

     #include <stdio.h>
     FILE *popen(const char *command, const char *mode);

Parameters 

command          Is a string giving the command line for a command you
                 want to execute.

mode             Specifies the nature of the pipe you want to open.  This
                 can be the string "r" or "w".  See the following section
                 for more details.

Description 

popen() executes the command specified by command.  It does this as if it
spawns a child process with fork(), then the child process invokes the
shell sh with

     execl (shellpath, "sh", "-c", command, NULL);

where shellpath is the path name of the file that contains the shell.

popen() establishes a pipe between command and the process which executes
popen().  The result of popen() is a FILE * pointer that can be used to
read/write on this pipe.  If mode is "r", standard output from command is
piped to the process which calls popen().  Data shipped along this pipe
can be read with normal I/O calls using the FILE * pointer returned by
popen().  If mode is "w", output written to the pipe by the process which
calls popen() is sent as the standard input to command.

Streams opened with popen() should be closed with pclose().

Errors 

popen() returns NULL if it cannot create the pipe or the child process.
It sets errno to one of the values used by pipe() or fork().  popen() may
also set errno to:

EINVAL            CAUSE           The value of mode was invalid.
                  ACTION          Specify a valid value for mode.

See Also 

sh(1), pclose()



MPE/iX 5.0 Documentation