i have following test code:
public class testprocessbuilder { public static void main(string args[]) { string imagelocation = "/home/john/image"; string installcommand = "java -jar install.jar -install /home/john/install.properties"; processbuilder pb = new processbuilder(); pb.directory(new file(imagelocation)); pb.command(arrays.aslist(installcommand.split("\\+s"))); try { pb.start(); } catch(exception e) { e.printstacktrace(); system.out.println("failed run command"); } }
this gives me error:
cannot run program "java -jar install.jar -install /home/john/install.properties" (in directory "/home/john/"): error=2, no such file or directory
do have create separate list , manually add each tokenized item it. thought should work...
you should make sure path java folder exported. can use similar this:
public static void main(string[] args) { string command = "java"; string parameters = "-jar install.jar -install /home/john/install.properties"; processbuilder pb = new processbuilder(command, parameters); try { pb.start(); } catch (ioexception e) { e.printstacktrace(); } }
depends of need, use if want pass whole command in 1 string:
try { runtime.getruntime().exec("java -jar install.jar -install /home/john/install.properties"); } catch (ioexception e) { e.printstacktrace(); }
Comments
Post a Comment