Launching python script and get the result in stout in php
I have a python script abc.py
that prints out "开发者_运维百科ABC".
When I tried to launch this script to get the printed result in php with this code
<?php
$cmd = "/usr/bin/python abc.py";
$handle = popen($cmd, 'r');
$res = fread($handle, 8192);
pclose($handle);
# Now you can make pretty printer about it.
return $res;
?>
The $res
is empty.
And with $cmd = "/usr/bin/python abc.py 2>&1";
, I got this error message /usr/bin/python: can't open file 'abc.py': [Errno 13] Permission denied
.
What's wrong with this? I got same error even when I make the file abc.py accessible to everyone.
I used absolute path for python script, and changed the permission flags so that others can access, but nothing worked. I just copied the python scripts where the php scrips are located, and it works fine. I don't think this is the best way, though.
精彩评论