shell_exec()在"ls"上返回null [英] shell_exec() returning null on "ls"

查看:222
本文介绍了shell_exec()在"ls"上返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这段代码,我只想在另一个目录中创建保存列表,该目录中的php scrip位于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.

推荐答案

在shell命令的末尾添加2>&1以使STDERRSTDOUT都返回.

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 don't have the sufficient permissions to view the output in /root/, then the above code will return a Permission denied error message.

来源: http://php.net/manual/en/function.shell-exec .php#28994

这篇关于shell_exec()在"ls"上返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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