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"

posted @ 2021-09-04 14:33  动灵  阅读(609)  评论(0编辑  收藏  举报