Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

exec(3) [php man page]

EXEC(3) 								 1								   EXEC(3)

exec - Execute an external program

SYNOPSIS
string exec (string $command, [array &$output], [int &$return_var]) DESCRIPTION
exec(3) executes the given $command. PARAMETERS
o $command - The command that will be executed. o $output - If the $output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as , is not included in this array. Note that if the array already contains some elements, exec(3) will append to the end of the array. If you do not want the function to append elements, call unset(3) on the array before passing it to exec(3). o $return_var - If the $return_var argument is present along with the $output argument, then the return status of the executed command will be written to this variable. RETURN VALUES
The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru(3) function. To get the output of the executed command, be sure to set and use the $output parameter. EXAMPLES
Example #1 An exec(3) example <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?> NOTES
Warning When allowing user-supplied data to be passed to this function, use escapeshellarg(3) or escapeshellcmd(3) to ensure that users can- not trick the system into executing arbitrary commands. Note If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends. Note When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable. Warning With safe mode enabled, the command string is escaped with escapeshellcmd(3). Thus, echo y | echo x becomes echo y | echo x. SEE ALSO
system(3), passthru(3), escapeshellcmd(3), pcntl_exec(3), backtick operator. PHP Documentation Group EXEC(3)

Check Out this Related Man Page

POPEN(3)								 1								  POPEN(3)

popen - Opens process file pointer

SYNOPSIS
resource popen (string $command, string $mode) DESCRIPTION
Opens a pipe to a process executed by forking the command given by $command. PARAMETERS
o $command - The command o $mode - The mode RETURN VALUES
Returns a file pointer identical to that returned by fopen(3), except that it is unidirectional (may only be used for reading or writing) and must be closed with pclose(3). This pointer may be used with fgets(3), fgetss(3), and fwrite(3). When the mode is 'r', the returned file pointer equals to the STDOUT of the command, when the mode is 'w', the returned file pointer equals to the STDIN of the command. If an error occurs, returns FALSE. EXAMPLES
Example #1 popen(3) example <?php $handle = popen("/bin/ls", "r"); ?> If the command to be executed could not be found, a valid resource is returned. This may seem odd, but makes sense; it allows you to access any error message returned by the shell: Example #2 popen(3) example <?php error_reporting(E_ALL); /* Add redirection so we can get stderr. */ $handle = popen('/path/to/executable 2>&1', 'r'); echo "'$handle'; " . gettype($handle) . " "; $read = fread($handle, 2096); echo $read; pclose($handle); ?> NOTES
Note If you're looking for bi-directional support (two-way), use proc_open(3). Note When safe mode is enabled, you can only execute files within the safe_mode_exec_dir. For practical reasons, it is currently not allowed to have .. components in the path to the executable. Warning With safe mode enabled, the command string is escaped with escapeshellcmd(3). Thus, echo y | echo x becomes echo y | echo x. SEE ALSO
pclose(3), fopen(3), proc_open(3). PHP Documentation Group POPEN(3)
Man Page