Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    FILE *_popen( const char *command, const char *mode );
    FILE *_wpopen( const wchar_t *command, const wchar_t *mode );

Description:
    The _popen function executes the command specified by command and
    creates a pipe between the calling process and the executed command.

    Depending on the mode argument, the stream pointer returned may be used
    to read from or write to the pipe.

    The executed command has an environment the same as its parents.  The
    command will be started as follows:  spawnl(<shell_path>, <shell>, "-c",
    command, (char *)NULL);

    where <shell_path> is an unspecified path for the shell utility and
    <shell> is one of "command.com" (DOS, Windows 95) or "cmd.exe" (Windows
    NT, OS/2).

    The mode argument to _popen is a string that specifies an I/O mode for
    the pipe.

    Mode     Meaning

"r"
    The calling process will read from the standard output of the child
    process using the stream pointer returned by _popen.

"w"
    The calling process will write to the standard input of the child
    process using the stream pointer returned by _popen.

    The letter "t" may be added to any of the above modes to indicate that
    the file is (or must be) a text file (i.e., CR/LF pairs are converted to
    newline characters).

    The letter "b" may be added to any of the above modes to indicate that
    the file is (or must be) a binary file (an ANSI requirement for
    portability to systems that make a distinction between text and binary
    files).

    When default file translation is specified (i.e., no "t" or "b" is
    specified), the value of the global variable  _fmode establishes whether
    the file is to treated as a binary or a text file.  Unless this value is
    changed by the program, the default will be text mode.

    A stream opened by _popen should be closed by the  pclose function.

Returns:
    The _popen function returns a non-NULL stream pointer upon successful
    completion.  If _popen is unable to create either the pipe or the
    subprocess, a NULL stream pointer is returned and  errno is set
    appropriately.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    EINVAL
        The mode argument is invalid.

    _popen may also set  errno values as described by the  _pipe and  spawnl
    functions.

Example:
    /*
     * Executes a given program, converting all
     * output to upper case.
     */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>

    char   buffer[256];

    void main( int argc, char **argv )
      {
        int  i;
        int  c;
        FILE *f;

        for( i = 1; i < argc; i++ ) {
          strcat( buffer, argv[i] );
          strcat( buffer, " " );
        }

        if( ( f = _popen( buffer, "r" ) ) == NULL ) {
          perror( "_popen" );
          exit( 1 );
        }
        while( ( c = getc(f) ) != EOF ) {
          if( islower( c ) )
              c = toupper( c );
          putchar( c );
        }
        _pclose( f );
      }

Classification:
    WATCOM

Systems:
     _popen - Win32, OS/2 1.x(all), OS/2-32

    _wpopen - Win32, OS/2 1.x(all), OS/2-32

See Also:
    _pclose, perror, _pipe

See Also: _pclose _pipe

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson