Forum und email

system

(PHP 4, PHP 5)

system — Execute an external program and display the output

설명

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.

매개변수

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.

반환값

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

예제

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;
?>

주의

Warning

사용자가 입력한 데이터를 이 함수로 넘길 때는, escapeshellarg()escapeshellcmd()를 사용하여, 사용자가 어떠한 명령을 실행하여 시스템을 조작하지 못하게 하여야 합니다.

Note: 이 함수를 사용하여 프로그램을 백그라운드에서 실행시키려면, 프로그램의 출력이 파일이나 다른 출력 스트림을 향하게 해야 합니다. 그렇지 않으면, PHP는 프로그램이 종료할 때까지 멈춰있을 것입니다.

Note: 안전 모드에서 실행 명령은 safe_mode_exec_dir 안에서만 실행할 수 있습니다. 실용적인 이유로, 현재는 실행 경로에 ..을 허용하지 않습니다.

Warning

안전 모드에서 명령어는 escapeshellcmd()로 회피처리됩니다. 그러므로, echo y | echo xecho y \| echo x가 됩니다.