How to execute the cmd command in PHP

Source: Internet
Author: User
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 );

Related Article

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.