3

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.

azro
  • 47,041
  • 7
  • 30
  • 65
user2086359
  • 153
  • 2
  • 11
  • Possible duplicate of [How to set PATH environment variable in ProcessBuilder java in windows](https://stackoverflow.com/questions/26992165/how-to-set-path-environment-variable-in-processbuilder-java-in-windows) – dpr Aug 17 '17 at 13:27

0 Answers0