2

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?

ehsangh
  • 311
  • 2
  • 6
  • 16

1 Answers1

4

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);
Marcus Recck
  • 5,075
  • 2
  • 16
  • 26
  • 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 :) – px4n Jun 07 '12 at 18:26
  • Very true, but it's fair to assume it's not executable since he wasn't getting output to begin with. – Marcus Recck Jun 07 '12 at 18:29
  • @MarcusRecck so i added headers to the form.py and i added this link to the php: echo('CLICK'); which works! so directory is correct and the script runs fine. also, adding python did not do anything. still outputting null – ehsangh Jun 07 '12 at 19:09
  • I understand this is old, but, for Windows and possibly other machines, make sure python is located on your path. – DeadChex Jan 19 '14 at 00:44