popen

Initiates a pipe to a process.

Format

#include  <stdio.h>

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

Arguments

command
A pointer to a null-terminated string containing a shell command line.
type
A pointer to a null-terminated string containing an I/O mode. Because open files are shared, you can use a type r command as an input filter and a type w command as an output filter. Specify one of the following values for the type argument:

Description

This function creates a pipe between the calling program and a shell command awaiting execution. It returns a pointer to a FILE structure for the stream.
Note
When you use the popen function to invoke an output filter, beware of possible deadlock caused by output data remaining in the program buffer. You can avoid this by either using the setvbuf function to ensure that the output stream is unbuffered, or the fflush function to ensure that all buffered data is flushed before calling the pclose function.

See also fflush, pclose, and setvbuf in this section.

Return Values
A pointer to the FILE structure for the opened stream. 
NULL  Indicates an error. Unable to create files or processes.  


Previous Page | Next Page | Table of Contents | Index