Forum und email

system

(PHP 4, PHP 5)

system — Execute an external program and display the output

Popis

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

system() is just like the C version of the function in that it executes the given command and outputs the result.

The system() call also tries to automatically flush the web server's output buffer after each line of output if PHP is running as a server module.

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.

Parametre

command

The command that will be executed.

return_var

If the return_var argument is present, then the return status of the executed command will be written to this variable.

Vrátené hodnoty

Returns the last line of the command output on success, and FALSE on failure.

Príklady

Example#1 system() example

<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line system('ls'$retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' 
$last_line '
<hr />Return value: ' 
$retval;
?>

Poznámky

Warning

Ak povolíte, aby dáta prichádzajúce z užívateľského vstupu boli posielané tejto funkcii, potom by ste mali používať escapeshellarg() alebo escapeshellcmd() pre uistenie sa, že užívatelia nemôžu prelstiť systém na spracovanie ľubovoľných príkazov.

Note: Ak spustíte program využívajúci túto funkciu a chcete ho nechať bežať na pozadí, musíte sa uistiť, či je výstup tohto programu presmerovaný do súboru alebo nejakého iného výstupného prúdu lebo inak PHP zostane vysieť pokiaľ sa spracovanie programu neskončí.

Note: Keď je povolený safe mode, možete spúšťať len spustitelné súbory v rámci safe_mode_exec_dir. Z praktických dôvodov nie je momentálne povolené mať .. komponenty v ceste k spustiteľnému súboru.

Warning

S povoleným safe mode, sa so všetkými slovami následujúcimi za počiatočným reťazcom príkazu zaobchádza ako s jedným argumentom. Teda, echo y | echo x sa stáva echo "y | echo x".