PHP provides four methods for executing system external commands: exec (), passthru (), system (), and shell_exec (). The following describes the exec prototype: 1: stringexec (string $ command [, array $ output [, int $ return_var]) exec executes the command, but does not output all results, but returns the final result
PHP provides four methods for executing system external commands: exec (), passthru (), system (), and shell_exec (). The following describes the exec prototype: 1: string exec (string $ command [, array $ output [, int $ return_var]) exec executes the command, but does not output all results, but returns the final result.
PHP provides four methods for executing system external commands: exec (), passthru (), system (), and shell_exec:
1. exec
Prototype: string exec (string $ command [, array & $ output [, int & $ return_var])
Exec executes the command, but does not output all results, but returns the last line of the result. If you want to get all results, you can use the second parameter to output it to an array, each record in the array represents each row of output. If there are 10 rows of output results, the array has 10 records. So if you need to repeatedly output the results of calling different system external commands, you 'd better clear the array when outputting the results of each system external command to prevent confusion. The third parameter is used to obtain the status code for command execution. Generally, 0 is returned for successful execution. Example:
No output.
Output:
Array ([0] => list.txt [1] => list.txt. ln [2] => tcpdumpchinese album .doc [3] => test1 [4] => beijiao shipper hui.jpg [5] => surging tide)
2. passthru
Prototype: void passthru (string $ command [, int & $ return_var])
Difference from exec: passthru directly outputs the result without returning the result. You do not need to use echo to view the result.
Result:
List.txtlist.txt.lntcpdumpchinese album .doctest1beijiao hui.jpg
3. system
Prototype: string system (string $ command [, int & $ return_var])
It is basically the same as passthru, but the system returns the result and outputs it. (View the returned values of system and pssthru)
4. shell_exec
Is a variant of the anti-apostrophes (') operator.
Reference: http://hi.baidu.com/cszhi/item/d71d61f22feefe16ce9f32d1