如何从PHP脚本运行linux命令[重复]

时间:2022-07-07 01:07:18

Possible Duplicate:
php shell_exec() vs exec()

可能重复: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?

我也能够回显该功能的输出吗?

4 个解决方案

#1


12  

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.

最后,作为简写,您可以将要执行的命令包装在反引号中。

#2


4  

You can do what you want with the following code :

您可以使用以下代码执行所需操作:

system(command);

See http://php.net/system

见http://php.net/system

#3


3  

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()..

#4


0  

you can use

您可以使用

exec
shell_exec

http://php.net/manual/en/function.shell-exec.php

http://php.net/manual/en/function.shell-exec.php

#1


12  

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.

最后,作为简写,您可以将要执行的命令包装在反引号中。

#2


4  

You can do what you want with the following code :

您可以使用以下代码执行所需操作:

system(command);

See http://php.net/system

见http://php.net/system

#3


3  

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()..

#4


0  

you can use

您可以使用

exec
shell_exec

http://php.net/manual/en/function.shell-exec.php

http://php.net/manual/en/function.shell-exec.php