Home > Backend Development > PHP Tutorial > How to execute cmd command in PHP

How to execute cmd command in PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 08:57:33
Original
1352 people have browsed it
  1. exec("mkdir d:\test",$out);
  2. print_r($out);
  3. ?>
Copy the code

to execute the php file, it will Found that there is an additional test folder under the d drive.

Reference documentation: exec function analysis 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 0 or 1. If 0 is returned, the execution is successful, if 1 is returned, the execution fails. exec failed, debugging solution

Tips sharing: Use the pipe command, use 2>&1, the command will output the error during shell execution to the $output variable, and output the variable for analysis. For example: exec(‘convert a.jpg b.jpg’, $output, $return_val); change into:

  1. exec(‘convert a.jpg b.jpg 2>&1′, $output, $return_val);
  2. print_r($output);
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template