简体   繁体   中英

cant execute python script from php

here is my code in control.php:-

<?php
$output = shell_exec("/var/www/script.py");
?>

why i cant run the shell_exec() command when i run the php script..? it should call the script.py and execute the py script.. but, when i run the control.php script..

note that i tried to run a normal program by using php where i tried to open gedit by using the command below:-

 <?php exec('gedit');?>

the gedit is not executed..

anyone can help me?

Can you run "/var/www/script.py" in the BASH? if NOT, then check the script,make sure contain the following line:

#!/usr/bin/env python

then chmod +x script.py to make sure it is executable.

You probably need to specify python in shell_exec() explicitly:

$output = shell_exec("/usr/bin/python /var/www/script.py")

or

$output = shell_exec("python /var/www/script.py")

and you need to ensure that your script.py has a permission better than "-rwxrwxr-x" as your php probably is executed by a different user.

原因是因为php没有在桌面上写/读py脚本的权限..因此,只需将py的目录更改为与php文件相同的目录,然后平稳运行即可。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM