简体   繁体   English

shell_exec不运行某些shell命令

[英]shell_exec does not run some shell commands

For example, when I try to execute 例如,当我尝试执行

$output=shell_exec('ls -l');
echo "<pre>$output</pre>";

It succesfully prints the output of 'ls -l'. 它成功打印了“ ls -l”的输出。

However, I cannot run a shell script which simply creates a file: 但是,我无法运行仅创建文件的shell脚本:

shell_exec('sh /home/ubuntu/Desktop/myScript.sh');

Is it about user access permissions defined in apache? 与apache中定义的用户访问权限有关吗?

How can I fix it? 我该如何解决?

What output do you expect from that script? 您希望从该脚本获得什么输出? I shell_exec() will probably only output STDOUT, so if there's errors you will need to redirect them from STDERR like this: 我的shell_exec()可能只会输出STDOUT,因此,如果出现错误,您将需要从STDERR重定向它们,如下所示:

<command> 2>&1

I'm guessing here, but try it with just a simple echo statement in the shell script. 我在这里猜测,但是只需在shell脚本中使用简单的echo语句即可尝试。 See if that works. 看看是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM