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 as you can read in the answer.
$cmd = "$python $pyscript $filePath";
exec("$cmd", $output);
works like a charm. Changed single ticks to double.
my index.php file be like
I find it odd that the filePath of
C:\\wamp\\....
would work on a Linux machine. Anyway, have you tried NOT escaping the slashes?The issue can be related to several things, including OS specific methods of implementing the different program execution functions. I recommend just going through the different options, I always put the command into a single variable and then print out the variable so that I can see what I am about to run, if you saw two slashes, then you might know that there is no need to try to escape the slashes, however without printing it to the screen you wouldn't know.
Try going through the other process execution functions to see what works for you. http://www.php.net/manual/en/ref.exec.php
The one that I have found works MOST like running it at the command line, is the backtick operator, and then next is
system
try something like this.
EDIT: AHHH! I just figured it out, you are surrounding your command with single ticks '' which means the variable inside are not being replaced. Use double quotes instead. That WILL solve the problem, but I still recommend echoing the command out before you run it so that you would see the command you are running and you would be able to identify an issue like this.