PHP shell_exec仅适用于某些命令

问题描述:

我是一个完整的PHP(LAMP/WAMP/MAMP)菜鸟,并且遇到了试图从Web服务器运行shell命令的菜鸟之间的常见问题.我在Mac mini上安装了MAMP,我想从Android命令中收集输出,

I am a complete PHP (LAMP/WAMP/MAMP) noob and I'm running into what seems to be a common issue among noobs trying to run shell commands from a web server. I have a MAMP setup on a Mac mini and I want to collect the output from an Android command,

adb devices

所以我可以显示连接到我的Mac mini的设备的列表.每当我在PHP脚本中将命令传递给shell_exec时,我都会返回一个空字符串.经过几次网页搜索后,我无法弄清楚如何解决该问题.我尝试跑步

so I can display a list of devices attached to my mac mini. whenever I pass the command to shell_exec in my PHP script I get an empty string returned. I cannot figure out how to resolve the issue after several web searches. I tried running

shell_exec("who am i")

返回"Clifton",即启动MAMP的用户帐户的名称.我验证了相同的用户帐户可以执行"adb设备"命令. Android工具安装在该用户帐户的主文件夹中.我也尝试过将绝对路径传递给命令.至此,我确定这是一个配置问题,但是我不知道该配置什么或在哪里配置.

which returns "Clifton", the name of the user account that launched MAMP. I verified that this same user account can execute the "adb devices" command. The Android tools are installed in that user account's home folder. I've also tried passing the absolute path to the command. At this point, I am certain that is a configuration issue but I don't know what to configure or where.

尝试一下:

shell_exec("adb devices  2>&1")

来源: http://www.php.net/manual/zh/function .shell-exec.php#106250