php exec 返回的结果比直接进入命令行少

2022-01-06 00:00:00 linux php unix grep

我有一个 exec 命令,它的行为与通过 Penguinet 提供给 linux 的相同命令不同.

I have an exec command that is behaving differently than the same command given to linux through Penguinet.

 $res = exec('cd /mnt/mydirectory/; zcat log_file.gz');
 echo $res

将命令直接放入命令行时,我在日志文件中看到大约 100 个条目.但是,当我访问具有 exec() 命令的 PHP 页面时,我只看到 1 个.并且它的格式正确.为什么 PHP 只显示一个结果?如何让它显示文件的全部内容?

When putting the commands directly into the command line, I see about 100 entries in the log file. However when I access the PHP page that has the exec() command, I see only 1. And it is formatted correctly. Why does PHP show me only one result? How can I make it show the entire contents of the file?

似乎只返回最后一行.我该如何改变?

Seems this is only returning only the last line. How can I change that?

推荐答案

试试这个:

exec('cd /mnt/mydirectory/; zcat log_file.gz', $res);
print_r($res);

相关文章