Linux echo exec 工作但 exec 不
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7839699/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
echo exec working but exec not
提问by Udit Gupta
I am using red hat enterprise edition n try making a simple php page..
我正在使用红帽企业版尝试制作一个简单的 php 页面..
When I try with ...
当我尝试...
// html code
<?php
echo exec(<cmd>);
?>
// rest html code
Its working fine
它的工作正常
but when tried with ...
但是当尝试...
// html code
<?php
exec(<cmd>);
?>
// rest html code
Its not working
它不工作
even a simple command like cat,ls,etc not working and also I tried 2 > &1
then no error is printed .
即使是像 cat、ls 等简单的命令也不起作用,我也尝试过,2 > &1
然后没有打印错误。
What could be the possible error ???
可能的错误是什么???
采纳答案by Phill Pafford
Docs:
文档:
return a response from the command, you would need to print the response out as well
从命令返回响应,您还需要打印出响应
Example:
例子:
<?php
$response = array()
exec('whoami', $response);
print_r($response,true);
?>
回答by Udit Gupta
okkkkkkk ......... I solved the problem. Actually there were two issues ...
okkkkkkk .........我解决了这个问题。其实有两个问题...
The
apache
user searches its command in/usr/bin
folder by default and the command I was trying to use was located in/usr/local/bin
. So I need to create a soft link of that command in the/usr/bin
directory.Secondly ,
apache
is a less privilaged user than root so need to on thesticky bit
of command so that apache could successfully run the command.
该
apache
用户在搜索其命令/usr/bin
的文件夹在默认情况下,我试图使用命令位于/usr/local/bin
。所以我需要在/usr/bin
目录中创建该命令的软链接。其次,
apache
是比 root 权限更低的用户,因此需要使用sticky bit
of 命令,以便 apache 可以成功运行该命令。
I hope this will help someone else also who will face the same problem in future.
我希望这能帮助将来也面临同样问题的其他人。