PHP to execute cmd command, php execute cmd command
This article describes the following, in the PHP code to execute the CMD command method, described under the php.ini file configuration safe_mode parameter Support command execution method, the need for a friend reference.
Description
This section is implemented in the context of the WAMP package installation.
First, turn on php.ini, turn off safe mode Safe_mode = off, and then look at the list of disabled functions disable_functions = Proc_open, Popen, exec, System, shell_exec, remove exec.
PHP Code:
Copy the Code code as follows:
<?phpexec ("mkdir d:\\test", $out);p Rint_r ($out);? >
Executing the PHP file, you will find a test folder under the D drive.
Reference Documentation:
exec function parsing
EXEC syntax: string exec (String command, string [array], int [return_var]);
EXEC return Value: string
EXEC parameter description
command– commands to execute
array– is the output value
The return_var– is a return value of 0 or 1, and if return 0 succeeds, the execution fails with return of 1.
exec unsuccessful, debug scenario
Skill Sharing:
With the pipe command, using 2>&1, the command outputs the error of the shell execution to the $output variable, which can be analyzed by outputting the variable.
For example:
EXEC (' Convert a.jpg b.jpg ', $output, $return _val);
Modified to:
Copy the Code code as follows:
EXEC (' Convert a.jpg b.jpg 2>&1′, $output, $return _val);p rint_r ($output);
PHP calls CMD and executes the telnet command, and VBS can, but hopefully I can do it all, I don't know that or any other way.
VBS:
Set Ws=createobject ("Wscript.Shell") ws.run "cmd/c telnet 192.168.200.44"
How PHP executes cmd commands or bat processing-technical questions
The function is with these two exec (); system (); No, it should be your command to write wrong. $str =null;exec (\ "dir c: \", $STR);