Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executing python script from php under windows

Okay this works with my linux server but I'm testing my web site at home on my PC and am trying to get php to execute my python script and of course the \ are WINDOWS only the path changes when Im on my linux machine.

$pyscript = 'C:\\wamp\\www\\testing\\scripts\\imageHandle.py';
$python = 'C:\\Python27\\python.exe';
$filePath = 'C:\\wamp\\www\\testing\\uploads\\thumbs\\10-05-2012-523.jpeg'


exec('$python $pyscript $filePath', $output, $return );

this works on my linux machine but not my windows testing server. How do I get this to run on windows? Oh and this also works when running directly from the command prompt in windows

EDIT:

This is the solution:

exec("$python $pyscript $filePath", $output);

I used single quotes instead of double quotes before, changing the single quotes to double quotes fixed the problem.

like image 777
knittledan Avatar asked May 11 '12 03:05

knittledan


1 Answers

This is a very old thread, but still comes up among the first results in Google, so it is worth an update.

In 2020, Under Python 3.8 and Windows 10 the right solution is simply:

<?
$output = shell_exec('C:\path\to\pythonscript.py');
print ($output);
?>

Everything else will result in an error. Took me a good few hours to figure out.

like image 158
Zsolt Balla Avatar answered Sep 27 '22 18:09

Zsolt Balla