php用system后台运行命令不等待结果的用法

来源:互联网 发布:sja1000编程 编辑:程序博客网 时间:2024/05/16 15:15

system(“nohup ./test.py $s &”);

这个不会在后台运行,php会一直挂起直到test.py结束。

system(“nohup ./test.py $s >>log.txt &”);

这样写才能在后台运行因为system函数启动一个程序并希望保持在后台运行,

必须确保该程序的输出被重定向到一个文件或者其它输出流去,否则PHP 会在程序执行结束前挂起。

比如:

1、 system(“nohup ./test.py $s >>/tmp/output.txt &”);

2、 system(“nohup ./test.py $s > /dev/null 2>&1 &”); 

       (2>&1是错误输出转到标准输出,想读错误输出就加2>&1,不加读不到错误)


   或 system(“nohup ./test.py $s > /dev/null &”);

1 0
原创粉丝点击