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