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 返回的结果比直接进入命令行少
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
