&1', $output, $return_val);" ."/> &1', $output, $return_val);" .">

Home  >  Article  >  Backend Development  >  What should I do if php exec cannot get the value?

What should I do if php exec cannot get the value?

藏色散人
藏色散人Original
2021-12-13 09:55:191738browse

Solution to the problem that php exec cannot obtain the value: 1. Open the corresponding PHP code file; 2. Modify the code to "exec('convert a.jpg b.jpg 2>&1', $output, $ return_val);" That's it.

What should I do if php exec cannot get the value?

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

What should I do if php exec cannot get the value?

PHP's exec() function has no return value Troubleshooting method:

Exec is needed to secure imagemagic and the installation fails on many servers

exec() execution The external command fails without any error message.

There is no problem when exec executes a certain command on the command line, but an error occurs in PHP. This problem is 99.99% related to permissions, but the command executed by exec will not return an error. One trick is to use a pipeline command. Suppose your exec call is as follows:

exec('convert a.jpg b.jpg', $output, $return_val);

can be changed as follows:

exec('convert a.jpg b.jpg 2>&1', $output, $return_val);    
print_r($output);

Use 2>&1, the command will output the error during shell execution to the $output variable , output this variable to analyze.

Note: exec has 3 parameters. The first is the command to be executed. The second parameter is an array. The value of the array is generated after the first command is executed. , the execution status of the third parameter, 0 indicates success, others indicate failure.

There are three functions in php that can be used to execute external commands system, exec, and passthru.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php exec cannot get the value?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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