【发布时间】:2019-06-11 08:45:43
【问题描述】:
我尝试通过单个 php exec() 调用在后台执行两个 linux 命令。
我的第一个命令是备份一些文件:
cp -r ../source ../destination
备份完成后,第二个命令会创建一个文件“DONE.txt”:
touch ../destination/DONE.txt
此外,我基于 php 手册并使用以下后台 exec() 调用:
exec('bash -c "exec nohup setsid '.$twoCommands.' > /dev/null 2>&1 &"');
整个代码如下:
exec('bash -c "exec nohup setsid { cp -r ../source ../destination && touch ../destination/DONE.txt; } > /dev/null 2>&1 &"');
而且...它不起作用:) 但是为什么呢?
如果我只使用一个命令:
exec('bash -c "exec nohup setsid cp -r ../source ../destination > /dev/null 2>&1 &"');
效果很好:)
【问题讨论】:
-
如果您不将错误重定向到
/dev/null,您会看到什么错误?你确定当前目录是什么?你有权限吗?等等等等 -
如果我只使用一个命令: exec('bash -c "exec nohup setsid cp -r ../source ../destination > /dev/null 2>&1 &"');效果很好:)
标签: php linux command-line-interface exec