我在一个循环中运行一个简单的命令,命令本身就是ffmpeg,但我不相信它与问题有关,所以,我有:
exec($exec.' 2>&1', $output, $return); if($return) { foreach($output as $line) { file_put_contents($log_file, $line, FILE_APPEND); } }这样,如果命令出现任何问题,我可以读取日志中的输出。 它工作,但$ output包含命令的整个shell历史记录。 澄清:每次发生错误时,特定命令生成的所有输出(包括全天数百次成功执行)都会转储到文件中。 写入的5行错误应该是整个1000+行历史。 我在CentOS上使用完全相同的代码,它只给出了最近执行的实例生成的输出的预期输出。
I'm running a simple command in a loop the command itself is ffmpeg, but I do not believe it's related to the issue so, I have:
exec($exec.' 2>&1', $output, $return); if($return) { foreach($output as $line) { file_put_contents($log_file, $line, FILE_APPEND); } }This way, if anything goes wrong with the command I can read the output in the log. It works, however $output contains the entire shell history of the command. To clarify: every time an error occurs, all output that was generated by the particular command (including hundreds of successful executions from throughout the day) is dumped to the file. What should be a 5 line error being written is instead the entire 1000+ line history. I used the exact same code on CentOS and it gave me the expected output of only the output generated by the instance most recently executed.
最满意答案
从文档 :
请注意,如果数组已包含某些元素,则exec()将附加到数组的末尾。 如果您不希望函数附加元素,请在将数组传递给exec()之前调用数组上的unset () 。
我无法解释为什么它在CentOS上的工作方式不同。
From the documentation:
Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().
I can't explain why it worked differently on CentOS.
更多推荐
发布评论