php exec returns less results than entering into command line directly(php exec 返回的结果比直接进入命令行少)
问题描述
我有一个 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);
这篇关于php exec 返回的结果比直接进入命令行少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php exec 返回的结果比直接进入命令行少


- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01