I'm trying to run a program which is in my system path using ProcessBuilder
however at the moment I'm having to specify the full path to the executable.
Process p1 = new ProcessBuilder().inheritIO().command("mycommand","myarg").start();
Reader rdr = new InputStreamReader(p1.getInputStream());
StringBuilder sb = new StringBuilder();
for(int i; (i = rdr.read()) !=-1;) {
sb.append((char)i);
}
String var = sb.toString();
System.out.println(var);
I can run $mycommand myarg
from the bash terminal but if I try this in Java I get a file not found error. Is there any way to get this path in Java or to get Java to look in the system path for the executable? I need this to run on multiple machines where the executable will be in different places.