Contents / Previous / Next


Operation System (OS) Calls (manual)

string system ( string command [, int &return_var] ):

system() executes the given command and outputs the result.
If the return_var argument is present, the return status of the executed command will be written to this variable. system() returns the last line of the command output on success, and FALSE on failure.

If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. Parameters


string exec ( string command [, array &output [, int &return_var]] ):

exec() executes the given command.
If the output argument is present, the specified array will be filled with output from the command.
If the return_var argument is present along with the output argument, the return status of the executed command will be written to this variable.

Example, outputs the username that owns the running php/httpd process:

echo exec('whoami');


resource popen ( string command, string mode ):

Opens a pipe to a process executed by forking the command given by command.
Returns a file pointer identical to that returned by fopen(), except that it is unidirectional (may only be used for reading or writing) and must be closed with pclose(). This pointer may be used with fgets(), fgetss(), and fwrite().

Example:

   $handle = popen("/bin/ls", "r");
Example, access any error message returned by the shell:
$handle = popen('/path/to/spooge 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;
pclose($handle);