PHP执行命令,日志输出无需等待(PHP execute command and log outpu

2019-07-30 04:38发布

我用EXEC()来执行命令,Linux或Windows。

你如何执行命令,Linux和Windows,并记录输出,而不必等待?

我知道在Linux,不等待输出: command* > /dev/null 2>/dev/null &

和日志输出对于Linux: command* > /path/to/log.txt 2>/path/to/error.txt

你会如何去记录和一个命令将其设置为背景? 如何将窗户的样子吗?

Answer 1:

在Linux上,你可以这样做:

exec('command* > /dev/null 2>/dev/null &');

在Windows中,你可以这样做:

pclose(popen('start /B cmd /C "command* >NUL 2>NUL"', 'r'));

这两个例子中禁用输出和错误,那些去/dev/null (Linux)或NUL (视窗),这意味着它们被存储“无处”。

您可以与您的系统上的有效路径替换这些。

在Linux上,一个&末其放入背景。 在Windows上较为复杂,且需要start调用过程,并cmd允许流重定向。



文章来源: PHP execute command and log output without waiting