So here is my code:
System.out.print("hellow");
try {
int x;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("java CPU/memory");
BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line = null;
while((line = in.readLine())!=null) {
System.out.println(line);
}
proc.waitFor();
} catch (Throwable t)
{
t.printStackTrace();
}
$
When I run java CPU/CPU in cmd I get
“hellowhello” with exit value of 0
But when I run it in eclipse I just get
“hello” with exit value of 1
Any idea?
You have different system environment in executing from command string and executing from Eclipse.
Variables of environment are valuable : PATH, JAVA_HOME or JRE_HOME and your current worikng directory.
I use ProcessBuilder in cases, when I must be sure in environment, that is provided for external process like yours “java CPU/memory”.
I think that first of all your external process have wrong working directory.
In ProcessBuilder you can point on it with: