【问题标题】:Running python script on background using PHP shell_exec使用 PHP shell_exec 在后台运行 python 脚本
【发布时间】:2018-05-08 21:16:49
【问题描述】:

我有一个运行 TCP 服务器并无限期运行的 python 脚本。 该脚本在我的终端后台运行:

sudo python3 TCPServer.py &

但是当我使用 PHP shell_exec 命令时:

shell_exec('sudo python3 TCPServer.py &')

它执行但永远等待。我希望它在后台运行。

【问题讨论】:

    标签: php python raspberry-pi


    【解决方案1】:

    要使用shell_exec 在后台运行命令,必须将输出重定向到/dev/null。参考php nanual notes

    shell_exec("python3 TCPServer.py 2>&1 | tee -a /tmp/mylog 2>/dev/null >/dev/null &");
    

    【讨论】:

    • 谢谢!我一直在寻找什么。 :)
    猜你喜欢
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多