linux+php+shell_exec輸出null的原因


最近做了一個項目需要 php+shell_exec() 調用python,在win下能正常調用到,然而轉移到centos上時結果一直是null,各種嘗試后總結如下:

1.檢查 php.ini disable_functions= 中是否有shell_exec,若有則刪除,保存后重啟php

2.python 要用全路徑,比如 shell_exec('/opt/python37/bin/python3 /xxx/xx/xx/x.py'),而不是只寫 shell_exec('python3 /xxx/xx/xx/x.py')

3.可以在shell_exec()括號內字符串的最后加上 2>&1 以返回STDERR以及STDOUT。例如 shell_exec('python3 /xxx/xx/xx/x.py 2>&1') 它就報 "sh: python3: command not found\n"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM