通过Shell脚本运行Cordova-权限问题 [英] Running Cordova via a shell script - permission problem
问题描述
我有一个从PHP调用的shell脚本(称为test.sh).在脚本中,我简单地拥有:
I have a shell script (called test.sh) which is called from PHP. Within the script I simply have:
#!/bin/bash
echo $(whoami)
cordova platform version ios
如果我从终端中调用test.sh,它将正常工作并返回cordova ios版本.
If I call test.sh from within terminal it works fine and returns the cordova ios version.
如果我尝试使用PHP调用test.sh,我将得到:
If I try to call test.sh from with PHP I get:
cordova: not found
我已将apache更改为以我的用户名而不是_www来运行,但这没有用.
I have altered apache to run under my username instead of _www but that hasnt worked.
有人认为我是权限问题吗?
Can anyone point me in the right direction as I'm guessing it is a permissions issue?
我现在通过删除.sh文件并仅使用PHP脚本(在用户_www下)进一步简化了此操作
I have now simplified it further by removing the .sh file and just using the PHP script (under user _www)
exec('echo $(whoami) 2>&1', $output, $return_var);
print_r($output);
echo "<br><br>";
putenv("CORDOVA_HOME=/usr/local/bin/cordova");
exec('cordova -v 2>&1', $output, $return_var);
print_r($output);
注意:whoami效果很好,但仍未找到corvoda.
Note: whoami works fine but corvoda is still not found.
推荐答案
为解决此问题,我查看了从terminal和PHP返回的路径,它们都使用相同的用户名,但返回的路径详细信息不同.
To solve the problem I looked at the path returned from terminal and PHP, they were both using the same username but returned different path details.
添加到PHP后:
putenv("PATH=".getenv('PATH').":/Users/USERNAME/.sdkman/candidates/gradle/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands");
putenv("CORDOVA_HOME=/usr/local/bin/cordova");
它开始起作用.我现在在查找证书时遇到了问题,但是在调查之后将是一个不同的问题.
It began to work. I now have a problem with finding certificates but that will be a different question after investigating it.
这篇关于通过Shell脚本运行Cordova-权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!