Lawrence DeSouza
Lawrence DeSouza

Reputation: 1027

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

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

Upvotes: 0

Views: 293

Answers (2)

RohitJ
RohitJ

Reputation: 563

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

Upvotes: 0

ChristoKiwi
ChristoKiwi

Reputation: 289

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);

Upvotes: 1

Related Questions