I am trying to run a python script from php.
exec("../cgi-bin/form.py", $output);
var_dump($output);
I'm certain the path is correct, and that form.py is executable.
this is form.py
#!/usr/bin/env python
print "IN form.py'
However, this prints out NULL. I don't think the script is being executed. How do I make sure it is?
asked Jun 7, 2012 at 18:16
ehsangh
3312 gold badges6 silver badges16 bronze badges
-
If you type which python from the command line, it should give you the full path to the python executable. You can then use that path and enter it at the top of your form.py script.px4n– px4n2012年06月07日 18:23:36 +00:00Commented Jun 7, 2012 at 18:23
-
i don't have shell access :(.ehsangh– ehsangh2012年06月07日 18:46:14 +00:00Commented Jun 7, 2012 at 18:46
-
You can use php exec to run the command, I suspect the return value will be /usr/bin/python.px4n– px4n2012年06月07日 18:57:29 +00:00Commented Jun 7, 2012 at 18:57
-
@patyx7 echo exec("which python"); returns nothing.ehsangh– ehsangh2012年06月07日 19:06:44 +00:00Commented Jun 7, 2012 at 19:06
-
How about exec("/usr/bin/which python", $output); ?px4n– px4n2012年06月07日 19:19:15 +00:00Commented Jun 7, 2012 at 19:19
1 Answer 1
You're literally just typing in the location of the file. You need to tell exec to execute python with that script.
exec("python ../cgi-bin/form.py", $output);
answered Jun 7, 2012 at 18:19
Marcus Recck
5,0432 gold badges19 silver badges27 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
px4n
If he specifies the correct path to python within his script and has made sure his script is executable, then it shouldn't be necessary to add python to the exec command :)
Marcus Recck
Very true, but it's fair to assume it's not executable since he wasn't getting output to begin with.
ehsangh
@MarcusRecck so i added headers to the form.py and i added this link to the php: echo('<a href="../cgi-bin/form.py">CLICK</a>'); which works! so directory is correct and the script runs fine. also, adding python did not do anything. still outputting null
DeadChex
I understand this is old, but, for Windows and possibly other machines, make sure python is located on your path.
default