exec函数不返回所有行 [英] exec function not returning all rows

查看:91
本文介绍了exec函数不返回所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的awk命令按预期工作,并在命令提示符下返回2行.

My awk command works as expected and returns 2 lines at command prompt.

当我使用php"exec"函数时,它仅返回第二行.

When I use php "exec" function, it returns only the second line.

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

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

How do I return all output of shell command using PHP?

推荐答案

如果存在 output 参数,则指定的数组将被命令的每一行输出填充.尾随空格(例如\ n)不包含在此数组中.请注意,如果数组已经包含一些元素,则exec()将追加到数组的末尾.如果您不希望函数附加元素,请在将数组传递给exec()之前在数组上调用unset().

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

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

这篇关于exec函数不返回所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆