Nothing happens when trying to call python script from a PHP file on my localhost

295 Views Asked by At

This are the lines in question in my php file:

$eventid_arg = $_REQUEST['eventid'];
$pyresponse_str = system('python s_scrape.py $eventid_arg', $retval);

And I have done the following for s_scrape.py:

1- placed it in the same localhost folder as the php file. 
2- chown changed to www-data:www-data
3- chmod changed to 777 on both the .py and .pyc
4- made sure '#!/usr/bin/env python' is on the python file
2

There are 2 best solutions below

0
RohitJ On

You should use system() only if the python has no return output. You should use popen() if you intend on using stdin or stdout.

As indicated by the popen() documentation, this "returns a file pointer identical to that returned by fopen(), except that it is unidirectional (may only be used for reading or writing) and must be closed with pclose()."

1
ChristoKiwi On

I might be slightly off here but perhaps:

$pyresponse_str = system('python s_scrape.py $eventid_arg', $retval);

Simply needs double quotes to recognize $eventid_arg ?

$pyresponse_str = system("python s_scrape.py $eventid_arg", $retval);