Runtime.exec() fails with space in directory (Java) -
i trying execute process in same directory jar file getting location of file with
private static file jarlocation = new file(main.class.getprotectiondomain().getcodesource().getlocation().getpath()).getparentfile();
then calling
runtime.getruntime().exec("command", null, jarlocation);
this works fine when path has space in "the directory name invalid". have attempted add debug code prints path of directory has replaced spaces "%20" (i assume because ascii hex of space 20). there way able use directory spaces in path?
that getpath()
call, url.getpath()
, not return filesystem path. returns path portion of url. in case of file:
url, url-encoded local filesystem path. if original url in fact file:
url, need use uri , url classes, or custom string processing, convert local filesystem path runtime.exec()
can work with.
this might work directly in case.
file jarlocation = paths.get(main.class.getprotectiondomain().getcodesource().getlocation().touri()).tofile();
you can see discussion @ converting java file:// url file(...) path, platform independent, including unc paths.
Comments
Post a Comment