gpt4 book ai didi

php - exec 函数不返回所有行

转载 作者:可可西里 更新时间:2023-10-31 23:05:16 26 4
gpt4 key购买 nike

我的 awk 命令按预期工作并在命令提示符处返回 2 行。

当我使用 php 的“exec”函数时,它只返回第二行。

echo exec("awk -v RS=\",\" '/some_text/' test1.html");

如何使用 PHP 返回 shell 命令的所有输出?

最佳答案

Return Values

The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

Returns false on failure.

To get the output of the executed command, be sure to set and use the output parameter.

它只返回最后一行输出所以使用:

output

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. 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().

http://php.net/manual/en/function.exec.php

exec("awk -v RS=\",\" '/some_text/' test1.html", $out);
foreach($out as $line) {
echo $line;
}

关于php - exec 函数不返回所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6339269/

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