This article mainly introduces how to execute the cmd command in PHP. if you need it, refer to this article to introduce how to execute the cmd command in php code. the safe_mode parameter configured in the INI file supports command execution methods. For more information, see.
Note:
This section is implemented in the wamp package installation environment.
First, open php. ini, turn off the safe mode safe_mode = off, and then look at the disabled function list disable_functions = proc_open, popen, exec, system, shell_exec to remove exec.
Php code:
The code is as follows:
<? Php
Exec ("mkdir d: \ test", $ out );
Print_r ($ out );
?>
Run the php file and you will find a test folder added to drive D.
Reference:
Exec function parsing
Exec syntax: string exec (string command, string [array], int [return_var]);
Exec return value: string
Exec parameter description
Command-Command to be executed
Array-is the output value
Return_var-returns 0 or 1. if 0 is returned, the execution is successful. if 1 is returned, the execution fails.
Exec failed, debugging solution
Tips:
With the pipeline Command 2> & 1, the command will output the $ output variable error during shell execution and output the variable for analysis.
For example:
Exec ('convert a.jpg B .jpg ', $ output, $ return_val );
To:
The code is as follows:
Exec ('convert a.jpg B .jpg 2> & 1', $ output, $ return_val );
Print_r ($ output );