How to execute the cmd command in PHP _php tips

Source: Internet
Author: User
Tags safe mode

This article describes, in the PHP code to execute the CMD command method, introduced in the php.ini file to configure Safe_mode parameters to support the implementation of the command method, the need for a friend reference.

Description
The contents of this section are implemented in the context of the WAMP package installation.

First, turn on the php.ini, turn off safe mode Safe_mode = off, and then look at the disabled function List disable_functions = Proc_open, Popen, exec, System, shell_exec, remove exec.
PHP Code:

Copy Code code as follows:

<?php
EXEC ("mkdir d:\\test", $out);
Print_r ($out);
?>

If you execute the PHP file, you will find a test folder on the D disk.

Reference Documentation:

exec function parsing
EXEC syntax: string exec (String command, string [array], int [return_var]);
EXEC return Value: string

EXEC parameter description
command– the command to be executed
array– is the output value
return_var– is the return value of 0 or 1, and if 0 is returned, the execution succeeds, and the return 1 fails.
exec unsuccessful, debug scenario

Skill Sharing:

Using the pipe command, using 2>&1, the command will output the error from the shell execution to the $output variable, and the variable can be parsed.

For example:

EXEC (' Convert a.jpg b.jpg ', $output, $return _val);
Modified to:

Copy Code code as follows:

EXEC (' Convert a.jpg b.jpg 2>&1′, $output, $return _val);
Print_r ($output);

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.