I have 2 scenarios below. One where I use the Runtime.getRuntime().exec method with arguments this does not seems to work I get the error while running the bash script.
However if i use the exec method without passing any values to the exec parameters it works.
String cfenv_location="bash /root/.cfenv/environments/ussouth_ys1/bin/cf ";
Process p = Runtime.getRuntime().exec(new String[]{cfenv_location, "create-service", servicename, planname, appname.replaceAll(" ", "-")});
Error:
exception happened - here's what I know:
java.io.IOException: Cannot run program "bash /root/.cfenv/environments/ussouth_ys1/bin/cf": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at java.lang.Runtime.exec(Runtime.java:485)
at JavaRunCommand.cfCreateService(JavaRunCommand.java:111)
at JavaRunCommand.main(JavaRunCommand.java:359)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 4 more
Works
String cfenv_location="bash /root/.cfenv/environments/ussouth_ys1/bin/cf ";
String command = cfenv_location+"login -a "+urllocation+ " -u "+username+ " -p "+password+ " -o "+org+" -s "+space;
Process p = Runtime.getRuntime().exec(command);
bashas command and the rest as parameters...cfenv_locationvariable, right? Please update the question with all you tried (and error messages), to prevent others to ask the same...