0

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()"

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try Make a sh file to execute the python script and use PHP to execute this sh file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.