让我们以此命令为例:
$command = "echo '/just/for/the/test /heh/' | awk '//just// {print $1}'";
Run Code Online (Sandbox Code Playgroud)
直接在shell中复制它时,我收到以下错误:
awk: cmd. line:1: //just// {print $1}
awk: cmd. line:1: ^ unterminated regexp
Run Code Online (Sandbox Code Playgroud)
但是,当我,exec()它得到状态代码1没有输出:
exec($command, $output, $status);
var_dump( $command, $output, $status );
// string(69) "echo '/just/for/the/test /heh/' | awk '//just// {print $1}'"
// array(0) { }
// int(1)
Run Code Online (Sandbox Code Playgroud)
如何检索exec的STDERR部分?
你应该像这样将stderr重定向到stdout
$stout = exec($command . " 2>&1", $output, $status);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
660 次 |
| 最近记录: |