php - 需要帮助理解 bash 命令

标签 php bash

其实是php和bash的结合:

exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));

我不明白 2>&1 & echo $! 有什么用?

最佳答案

2>&1 redirects stderr to stdout , 和 $! "Expands to the process ID of the most recently executed background (asynchronous) command".

所以,这是发生了什么:

  1. 您将 $cmd 的 stderr 和 stdout 都发送到名为 $outputfile 的文件。如果您没有执行 2>&1,您将无法读取文件中的 stderr 输出。
  2. 后面的&表示进程runs in the background .
  3. 然后将 $cmd 的 PID(通过 $! 获得)附加到 $pidfile 的末尾。

关于php - 需要帮助理解 bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2432578/

相关文章:

php - FPDF 中的 While 循环仅打印 1 个结果

php - 沙盒模式下的 Paypal IPN

linux - 如何将错误输出发送到 bash 中的 stdout 和文件

macos - .profile 无法在 Mac 的终端上运行

bash - 通过命令退出代码打印不同的消息

linux - 在 Linux 上,完全清空一个目录而不删除它的正确方法是什么?

bash - 在bash脚本中减去两个时间戳

php - 根据整数调用函数

php - 如何从使用 jquery 的 foreach 循环生成的表单中的输入字段中获取值

php - Doctrine_Table 中的查询生成器?