简体   繁体   中英

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.

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.

<?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. But I am getting nothing.

Some functions just print back "Array()"

You are running pythin script from apache user. Python path may not be accessible by apache user

Use full python installation path to execute script.

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

To find out exact error check apache error log. If error logs give permission denied , it means apache is not having permission to execute script. You can get access from sudoers file.

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

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