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