"Problem grooming" PHP calls Python script without display problem

Source: Internet
Author: User

Environment: Windows Server2008+apache+php+mysql

Problem: The shell can perform successfully, but PHP calls Python is not

To develop a project, you need to invoke the Python command in PHP, as follows:

$cmd = ' python main.py-u '; EXEC ($cmd, $res);

The result $res what return value is not, this is embarrassed ... So the wrong, Apache Error_log is a good thing AH ~ ~ What error will appear in the log file, of course, you can also write 2>&1 after the command to make the error echo in $res, like this:

$cmd = ' python main.py-u 2>&1 ';

The error is displayed as Python is not an internal or external command, this should be an environmental variable problem, in short, after a long brain pumping to find a solution:

Although the system environment variables are configured, PHP and Shell should not be a library, so the workaround is simple, change the command to the following.

$cmd = ' C:/python27/python main.py-u http://www.example.com '

Where c:/python27 is the path of its own python

Summary: Every time you solve a problem, you feel like a retarded person. Spending too much time on simple questions, solving problems may not take too much time, and it takes time to find the cause of the problem. In the sauce, want to be more powerful, write something with technical content.

This article is from the "hesitated" blog, make sure to keep this source http://chichu.blog.51cto.com/11287515/1963098

"Problem grooming" PHP calls Python script without display problem

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.