gpt4 book ai didi

php - exec() 错误响应

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:09:23 24 4
gpt4 key购买 nike

让我们以这个命令为例:

$command = "echo '/just/for/the/test /heh/' | awk '//just// {print $1}'";

在shell中直接复制时,出现如下错误:

awk: cmd. line:1: //just// {print $1}
awk: cmd. line:1: ^ unterminated regexp

但是,当我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)

如何获取exec的STDERR部分?

最佳答案

你应该像这样将 stderr 重定向到 stdout

$stout = exec($command . " 2>&1", $output, $status);

另见此处 PHP StdErr after Exec()

关于php - exec() 错误响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12472220/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com