I am trying to execute in linux:
command[0] = "~/test/bin/runScript_sh";
Runtime.getRuntime().exec(command);
But get an exception
java.io.IOException: Cannot run program
error=2, No such file or directory
Probably because it can not evaluate tilde.
What can be done?
I would replace it myself.
if(path.s.substring(0,1).contains("~"))
path = path.replaceFirst("~",System.getProperty("user.home"));
Which gets you the string you want.
You can get the user's home directory with System.getProperty:
command[0] = System.getProperty("user.home") + "/test/bin/runScript_sh";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With