popen

resource popen(string command, string mode) 

Opens a pipe.

Returns:

File pointer

Description:

This function forks the program specified in command and opens a pipe to it. The pipe can only be unidirectional; that is, only read or write operations are allowed. The returned handle can be treated like a file handle, using fgetss(), fgets(), and fputs(). The mode argument can be either r (read) or w (write).

Warning:

3.0.11: popen() mistakenly renamed to _popen() on Windows, thus issuing error messages when trying to access popen() on Windows machines.

Example:

Output a directory using a pipe to ls
 if(!$fh = popen("/bin/ls", "r")) { echo ("Could not fork ls"); } while(!feof($fh)) { $output = fgets($fh, 1024); echo ("$output<br />"); } pclose($fh); ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.