问题
I am trying to call Btrace script from Spring web application deployed on cloudfoundry.
The execution command is /var/vcap/data/dea/apps/petclinic-0-fef4b0e052097a0cd2bedb8018c28dcd/tomcat/webapps/ROOT/WEB-INF/classes/bin/btrace.sh 532 /var/vcap/data/dea/apps/petclinic-0-fef4b0e052097a0cd2bedb8018c28dcd/tomcat/webapps/ROOT/WEB-INF/classes/bin/DatabaseQueries.java
But I get this error:
java.io.IOException: Cannot run program "/var/vcap/data/dea/apps/petclinic-0-fef4b0e052097a0cd2bedb8018c28dcd/tomcat/webapps/ROOT/WEB-INF/classes/bin/btrace.sh": java.io.IOException: error=13, Permission denied
I push the app with full permissions to script but error persists.
How can we execute a shell/bat script from spring web application on cloudfoundry
回答1:
Permissions on files pushed to Cloud Foundry are read/write by the file owner. You'll need to make the script executable from your app before running it:
String btracePath = System.getenv().get("HOME") + "/tomcat/webapps/ROOT/WEB-INF/classes/bin/btrace.sh";
String cmd = "chmod +x " + btracePath;
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
try {
pr.waitFor();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
来源:https://stackoverflow.com/questions/11338815/execute-shell-script-from-spring-web-application-deployed-on-cloudfoundry