Initiates a pipe to a process. Format #include <stdio.h> FILE *popen (const char *command, const char *type);
1 – 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: o r-the calling program can read from the standard output of the command by reading from the returned file stream. o w-the calling program can write to the standard input of the command by writing to the returned file stream.
2 – Description
The popen 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. The popen function uses the value of the DECC$PIPE_BUFFER_SIZE feature logical to set the buffer size of the mailbox it creates for the pipe. You can specify a DECC$PIPE_BUFFER_SIZE value of 512 to 65024 bytes. If DECC$PIPE_BUFFER_SIZE is not specified, the default buffer size of 512 is used. NOTES o 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. o For added UNIX portability, you can use the following feature logicals to control the behavior of the C RTL pipe implementation: - Define the DECC$STREAM_PIPE feature logical name to ENABLE to direct the pipe function to use stream I/O instead of record I/O. - Define the DECC$POPEN_NO_CRLF_REC_ATTR feature logical to ENABLE to prevent CR/LF carriage control from being added to pipe records for pipes opened with the popen function. Be aware that enabling this feature might result in undesired behavior from other functions such as gets that rely on the carriage-return character. See also fflush, pclose, and setvbuf.
3 – Return Values
x A pointer to the FILE structure for the opened stream. NULL Indicates an error. Unable to create files or processes.