PHP to execute cmd command method, php execute cmd command _php tutorial

Source: Internet
Author: User

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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.