PHP shell_exec only works for certain commands

余生长醉 提交于 2019-12-21 20:49:44

问题


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

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")

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.


回答1:


Try this:

shell_exec("adb devices  2>&1")

Source: http://www.php.net/manual/en/function.shell-exec.php#106250




回答2:


You should try to open the file /Applications/MAMP/Library/bin/envvars and then comment the four lines of if and else. This is looks like this:

#if test "x$DYLD_LIBRARY_PATH" != "x" ; then
#  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#else
#  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"

It works fine for me! I hope that you can enjoy it. Good Lucky!



来源:https://stackoverflow.com/questions/10640045/php-shell-exec-only-works-for-certain-commands

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!