popen()

open a pipe stream and execute command 

Function


SYNOPSIS

#include <stdio.h>

FILE *popen(const char *command, const char *mode);


DESCRIPTION

The popen() function executes the specified command. It creates a pipe between the calling program and the executed command, and returns a pointer to a stream that can be used to either read from or write to the pipe. The popen() function passes the command to the host environment so that a command processor can execute it.

The popen() command ensures that any streams from a previous popen() call that remain open in the parent process are closed in the new child process.

The requested mode string specifies the I/O mode:

After popen() returns, both the parent and the child process are capable of executing independently before either terminates.


PARAMETERS

command 

Points to a null-terminated string consisting of a shell command line.

mode 

Points to a null-terminated string consisting of an I/O mode, as described in the DESCRIPTION section.


RETURN VALUES

If successful, popen() returns a stream pointer. If files or processes cannot be created, it returns a null pointer, and sets errno to one of the following values:

EINVAL 

The mode parameter is invalid.

EMFILE 

No more files or streams can be created.


CONFORMANCE

POSIX.1 (1996), with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

There is no default shell in the Window environment. Hence the NuTCRACKER Platform first checks for SHELL in the environment to determine the shell to use, and then checks COMSPEC for a fall-back command interpreter. If neither is set, then popen() fails. The NuTCRACKER Platform implements popen() using _NutForkExeclp(); refer to that function for more information on how the command processor is invoked.

The NuTCRACKER Platform supports text and binary modes for the pipe. Refer for fopen() for more information on mode flags.

You must ensure that any path name arguments you pass to non-NuTCRACKER Platform applications are in Win32 format, as only NuTCRACKER Platform applications recognize the NuTCRACKER Platform format. Refer to Path Names in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for more information.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
_NutForkExeclp(), fopen(), pclose(), pipe(), system()


PTC MKS Toolkit 10.5 Documentation Build 40.