shell_exec() returning null on quot;lsquot;(shell_exec() 在“ls上返回 null)
问题描述
所以我有这段代码,我只是想在另一个目录中列出保存列表,其中 php 脚本位于 xampp 文件夹中,并且保存到此路径 /root/files/saves代码>:
So I have this code and I'm only trying to make a list of the saves in another directory where the php scrip is in xampp folder and the saves are to this path /root/files/saves:
<html>
<body>
<?php
$output = shell_exec('ls /root/files/saves');
echo "<pre>$output</pre>";
?>
</body>
</html>
我不知道为什么我不能让它在 var_dump 上运行它似乎输出为空我真的很困惑它应该工作或者我完全错了我需要一些帮助.
I don't know why I can't get it working on a var_dump it seems output is null I'm really confuse it should work or I just it all wrong I need some help.
推荐答案
将 2>&1 添加到您的 shell 命令的末尾以使 STDERR 也返回作为 STDOUT.
Add 2>&1 to the end of your shell command to have STDERR returned as well as STDOUT.
$output = shell_exec("ls /root/files/saves 2>&1");
另外,如果运行 PHP 的用户没有足够的权限查看 /root/ 中的输出,上述代码将返回 Permission denied 错误消息.
Also, if the user running PHP doesn't have sufficient permissions to view the output in /root/, the above code will return a Permission denied error message.
来源:http://php.net/manual/en/function.shell-exec.php#28994
这篇关于shell_exec() 在“ls"上返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:shell_exec() 在“ls"上返回 null
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何替换eregi() 2022-01-01
