Go to: Synopsis. Return value. Related. MEL examples.

Synopsis

popen <string> <string>

popen is undoable, queryable, and editable.

Like fopen, popen opens a file for reading or writing depending on the second mode argument ("r" or "w"). The command is executed using the system function call and a pipe is created from that command's input or output. If popen returns 0 something went wrong. The standard file functions for reading and writing to/from a file may be used on the pipe opened by popen (fprint, fgetword, fgetline etc).

Return value


int

Related

fclose, feof, fflush, fgetline, fgetword, fopen, fprint, fread, frewind, fwrite, pclose, system

MEL examples

// Unix specific example.  Note: if you really want to get a directory
// listing, please use the "getFileList" command instead.  This is just
// used as a simple example.
//
$pipe = popen( "ls -1", "r" );
string $dirList[];
while ( !feof( $pipe ) ) {
    $dirList[size( $dirList )] = fgetline( $pipe );
}
pclose( $pipe );

// Windows specific example.  Note: if you really want to get a directory
// listing, please use the "getFileList" command instead.  This is just
// used as a simple example.
//
$pipe = popen( "DIR /B", "r" );
string $dirList[];
while ( !feof( $pipe ) ) {
    $dirList[size( $dirList )] = fgetline( $pipe );
}
pclose( $pipe );