penguinrob
penguinrob

Reputation: 1459

PHP not executing python script correctly

I'm executing a python script from a php page like so: exec("python ./test.py");

This script runs fine if I don't open a serial port in it. If I do, however, (and this is the whole point of calling the python script in the first place), the script doesn't execute properly.

If I call a simple python script that prints a statement -

print "This works!"

Then I get the desired output in my php page. But, if I open a serial port, I no longer get the output of "This works!", and the serial data is not getting sent to the receiving device -

import serial
ser = serial.Serial("/dev/ttyACM0",9600)
print "This works!"

Both scripts run fine from the command line.

Is this a php limitation? I have tried other methods of execution such as popen and system, but they didn't work for me either.

Upvotes: 0

Views: 643

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375992

Perhaps you aren't getting complete error reporting from your Python execution. Try adding raise Exception('Boo!') as the first line of you Python program to find out if you are or not. If you don't get the exception and a traceback, then your program is probably failing on the serial.Serial line, but you aren't hearing about it.

Upvotes: 2

Related Questions