简体   繁体   中英

exec python in php problems

In the php code exec('python file.py 1 2',$result);

the $result give me the code inside the file.py but I need the output from print. Suppose file.py do an addition job.

var_dump($result) -> import sys print int(sys.argv[1]) + int(sys.argv[2])

instead of var_dump($result) -> 3

Also got this problem when using exec('php file.php 1 2',$result) .

safe_mode is already turn off

You should tell more about the the platform you are trying to execute the script on.

Back to the question, I'd guess that you didn't properly point to the path of the Python interpreter - try something like this: exec('C:\\\\python27\\\\python.exe file.py 1 2',$output);

$value = exec('python /var/www/neptenderapp/upload/hough.py ' . $_FILES["file"]["name"]); The last output of your python script will be sent as value to this variable $value . While executing the python script, you could give full path to the python script in the php exec command and do a os.chdir('/var/www/upload') at the beginning of your python script as well. If you have any problems, please do visit once, this link where I have documented how I solved my problem similar to yours. If further problem arises, do keep asking for more answers in here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM