Skip to content Skip to sidebar Skip to footer

Php Exec Python Not Working

hey yall. Im running python on a webserver from dreamhost. I am using their install of python and am using a lastfm module that can be found here: http://code.google.com/p/python

Solution 1:

Try using the full path to the python executable. For example:

exec("/usr/bin/python test.py")

You can find the full path from the command line using the which command:

$ which python /usr/bin/python

Solution 2:

Whatever error python is raising would be going to the child's stderr. Try either telling php to read from stderr, or (in python) do this:

import sys
sys.stderr = sys.stdout

Solution 3:

For Windows users:

$output = null;
exec('C:\\Python27\\python.exe C:\\sud.py', $output);
echo var_export($output, TRUE);

The code i was searching whole day ^^ That's why - hope it'll help somebody.

Solution 4:

For Windows User - Thanks to Karlisup my PHP file could read python. I'm using BITNAMI WAMP in EC2 Amazon, my python file (leadatos.py) and php file are on htdocs folder.

My calling was

<?php
  passthru('C:\\Python27\\python.exe leadatos.py');
 ?>

The last line of my Python file was print "message".

Hope it words!

Post a Comment for "Php Exec Python Not Working"