使用PHP执行Unix Shell命令 [英] Executing unix shell commands using PHP

查看:77
本文介绍了使用PHP执行Unix Shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将使用文本框捕获命令.有人告诉我必须使用exec()函数来执行UNIX shell命令.

A text box will be used to capture the command. I've been told that I have to use the exec() function to execute UNIX shell commands.

类似这样的情况,用户在文本框中键入ls. exec()函数将执行UNIX命令,该命令将显示在网页上.

Something like this, user types ls in the text box. The exec() function will execute the UNIX command and the command will be displayed on the web page.

我想知道如何获取shell命令的输出并使用PHP在Web浏览器中显示.

What I want to know how will I get the output of the shell command and display in the web browser using PHP.

由于我是PHP的新手,所以我不知道从哪里开始.

I don't know where to start since I'm very new to PHP.

我正在使用Ubuntu.

I'm using Ubuntu.

推荐答案

您可以开始查看php手册:

You could start looking at the php manual:

系统程序执行

但是就像sdleihssirhc提到的那样,当心这是非常危险的,您应该允许一切执行!
如果仍要执行此操作,则要获取外壳程序的输出,只需使用

But like sdleihssirhc mentioned, watchout this IS very dangerous and you should NOT allow everything to be executed!
If you still want to do it, to get the output of the shell, just use

exec
Shell的输出将在第二个参数中传递.

exec
The output of the shell will be passed in the second parameter.

例如:

exec('ls -la', $outputArray);
print_r($outputArray);

这篇关于使用PHP执行Unix Shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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