简体   繁体   English

使用PHP从HTML按钮执行python脚本时出现问题

[英]Issues executing python script from HTML button using PHP

I cannot get a button on my webpage to execute a python3 script that is also inside the same folder in the server as the rest of the html and php files. 我无法在网页上获得执行python3脚本的按钮,该脚本也与其余html和php文件位于服务器的同一文件夹内。

exec();
system();
escapeshellcmd();
shell_exec()

all of these commands are not working for me right now. 所有这些命令现在都不适用于我。 I have chmod +x my .py file and included #!/usr/bin/env python3 at the very beginning of my python file. 我有chmod + x我的.py文件,并在我的python文件的开头包含#!/ usr / bin / env python3。

<?php
if( isset($_POST['runScript'])){

$command = escapeshellcmd('/nfs/nfs7/home/team51/cgi- 
pub/dataProcess.py');
$output = shell_exec($command);
echo $output;

}
?>

<form method="post">
<input type="submit" name="runScript" value="runScript">
</form>

In the end the python script should place a csv file in the same folder as the rest of the files. 最后,python脚本应将一个csv文件放置在与其余文件相同的文件夹中。 But I am getting nothing. 但是我什么也没得到。

Some functions just print back "Array()" 有些功能只是打印回“ Array()”

You are running pythin script from apache user. 您正在从apache用户运行pythin脚本。 Python path may not be accessible by apache user apache用户可能无法访问Python路径

Use full python installation path to execute script. 使用完整的python安装路径执行脚本。

exec("/usr/bin/python /nfs/nfs7/home/team51/cgi- 
pub/dataProcess.py");

To find out exact error check apache error log. 要找出确切的错误,请检查apache错误日志。 If error logs give permission denied , it means apache is not having permission to execute script. 如果错误日志的权限被拒绝,则表明apache没有执行脚本的权限。 You can get access from sudoers file. 您可以从sudoers文件获得访问权限。

尝试制作一个sh文件以执行python脚本,并使用PHP执行该sh文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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