Running Cordova via a shell script - permission problem

北战南征 提交于 2020-06-17 15:50:05

问题


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

If I call test.sh from within terminal it works fine and returns the cordova ios version.

If I try to call test.sh from with PHP I get:

cordova: not found

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?


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

Note: whoami works fine but corvoda is still not found.


回答1:


Use npm to install Cordova globally. right now Cordova is not available in your host globally. So make it globally first.

on OS X and Linux:

sudo npm install -g cordova

on Windows:

C:\>npm install -g cordova



回答2:


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.

After adding to 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.



来源:https://stackoverflow.com/questions/62154071/running-cordova-via-a-shell-script-permission-problem

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