如何从 PHP 脚本运行 linux 命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12830520/
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
How can I run a linux command from a PHP script
提问by DonJuma
Possible Duplicate:
php shell_exec() vs exec()
How do I run a linux command from a PHP script? I'm running Linux Debian and PHP5. I want to be able to issue a wget
command to the console.
如何从 PHP 脚本运行 linux 命令?我正在运行 Linux Debian 和 PHP5。我希望能够向wget
控制台发出命令。
An example of what I'm looking for is something like this:
我正在寻找的一个例子是这样的:
phpFunction ("wget http://www.example.com/image.jpg /folder");
echo "done";
Also would I be able to echo the output of that function?
我还能回显该函数的输出吗?
采纳答案by xbonez
Use exec
to run any command. Be careful not to exec any user input though, as it can severely compromise your server.
使用exec
运行任何命令。小心不要执行任何用户输入,因为它会严重损害您的服务器。
Also, note that most shared servers block off the exec
function so you won't be able to use it.
另请注意,大多数共享服务器会阻止该exec
功能,因此您将无法使用它。
Finally, as a shorthand, you can wrap the command you want to exec in backticks.
最后,作为速记,您可以将要执行的命令包装在反引号中。
回答by Gilles Quenot
You can do what you want with the following code :
您可以使用以下代码执行您想要的操作:
system(command);
回答by mahen3d
回答by Tajamul
You can execute linux commands within a php script - all you have to do is put the command line in brackits (`).
您可以在 php 脚本中执行 linux 命令 - 您所要做的就是将命令行放在括号 (`) 中。
And also concentrate on exec()
, this and shell_exec()
..
并且还专注于exec()
,这和shell_exec()
..