In PHP, how does one determine that the exec function is successfully executed ?, Php determines the exec Function

Source: Internet
Author: User

In PHP, how does one determine that the exec function is successfully executed ?, Php determines the exec Function

Preface

For a code publishing system, PHP'sExec FunctionTo execute commands andGit, svnCommand, how to determine the PHPExec FunctionIs the execution successful?

Solution

Write a PHP file to do the experiment:

Exec FunctionThe first parameter is the command to be executed, the second parameter is the result of execution, and the third parameter is the execution status.

<?phpexec('ls', $log, $status);print_r($log);print_r($status);echo PHP_EOL;

Run the PHP file:

Here$ Log, $ statusOutput result.

However$ Status0. The execution failed, not actually,The exec operation is successful..

Modify the PHP file and give the first exec parameter an incorrect command.

For example:exec(‘lsaa',$log,$status).

Run the command again and run the result.

Here$ StatusThere is indeed a value.

Then prove$ StatusIf the value is 0, exec execution is successful. The PHP official Manual does not explicitly describe this.

The method for executing the command is as follows:

Execute the PHP exec command

Public function runLocalCommand ($ command) {$ command = trim ($ command); $ status = 1; $ log = ''; exec ($ command. '2> & 1', $ log, $ status); // executed command $ this-> command = $ command; // execution status $ this-> status =! $ Status; return $ this-> status ;}

Remove log records and other judgments.

Note:

$this->status = !$status;

The opposite value is returned!

Summary

The above is the judgment in PHPExec FunctionWhether to execute the details of the successful execution and the instance code will help you gain an in-depth understanding of PHP development. I hope this article will help you learn PHP development.

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.