Execute shell script from spring web application deployed on cloudfoundry

你说的曾经没有我的故事 提交于 2019-12-08 01:10:13

问题


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

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