debian环境中的php exec()$ output包含整个shell历史记录(php exec() in debian environment $output contains entire s

编程入门 行业动态 更新时间:2024-10-28 15:26:00
debian环境中的php exec()$ output包含整个shell历史记录(php exec() in debian environment $output contains entire shell history)

我在一个循环中运行一个简单的命令,命令本身就是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.

更多推荐

本文发布于:2023-04-28 16:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1332460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:历史记录   环境   exec   debian   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!