Name

wpopen - process I/O

Library

libc.lib

Synopsis

  #include <wchar.h>
  FILE * wpopen (const wchar_t* command, const wchar_t* type );

Return values

The wpopen function returns NULL if the fork or pipe calls fail, or if it cannot allocate memory. And returns stream pointer on success.


Detailed description

The wpopen function opens a process by creating a pipe and invoking the shell (creating a process). Since a pipe is by definition unidirectional, The type argument may specify only reading or writing, not both; the resulting stream is correspondingly read-only ("r") or write-only "w". If type is anything other than this, then the behavior is undefined.

The command argument is a pointer to a null-terminated wide character string containing a shell command line. This command is passed to /bin/sh using the -c flag; interpretation, if any, is performed by the shell.

The return value from wpopen is a normal standard I/O stream in all respects save that it must be closed with pclose rather than fclose. Writing to such a stream writes to the standard input of the command; the command’s standard output is the same as that of the process that called wpopen, unless this is altered by the command itself. Conversely, reading from a "wpopened" stream reads the command’s standard output, and the command’s standard input is the same as that of the process that called wpopen.

Note that output wpopen streams are fully buffered by default.


Errors

The wpopen function does not reliably set errno.

See also

popen, pclose, pipe, fclose, fflush, fopen, system


Bugs

Since the standard input of a command opened for reading shares its seek offset with the process that called wpopen, if the original process has done a buffered read, the command’s input position may not be as expected. Similarly, the output from a command opened for writing may become intermingled with that of the original process. The latter can be avoided by calling fflush before wpopen.

Failure to execute the shell is indistinguishable from the shell’s failure to execute command, or an immediate exit of the command. The only hint is an exit status of 127.

The wpopen function always calls sh, never calls csh.


Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top