I need to call a PHP script from within python. I found this thread on StackOverflow:
So I use this exact method to call my php script. However, I get the following error:
php is not recognised as an internal or external command
First I figured it was because php wasn't in my PATH environment variable, so added it and it worked in my command line, but my Python script kept returning the same error. I also tried adding php to my PYTHONPATH, with the same result. I finally even tried to put the php file in the folder where the php executable is located, but this also didn't work.
What do I need to change in order for this to work?
EDIT
My operating system is Windows 7. This is the code I'm using:
proc = subprocess.Popen("php C:/xampp/htdocs/test/test.php", shell=True, stdout=subprocess.PIPE)
script_response = proc.stdout.read()
I didn't try to run my python script from my command line, which does not produce the error and executes the php script. The script_response
variable is empty however.
This is the last line of my test.php
file:
return $aResult;
I checked the $aResult
, it does contain a value so it's not returning properly. Do I need something else in my php script instead of return
?