Runtime.getRuntime().exec problem win serv 2003 versus win serv 2008
-
27-09-2019 - |
Question
I have some java code as follows:
try {
String outString ="java -jar C:\\ami\\bin\\ImmediateSubmit.jar 12345 localhost";
Runtime.getRuntime().exec(outString);
out.println("SUBMITTED");
}
catch (IOException e) {
System.out.println("IO Exception parse");
out.println("FAILED");
e.printStackTrace();
}
It works fine in win serv 2003 but not in win serv 2008.
Any ideas why?
Solution
Read both the stdout and stderr streams of the Process
returned by Runtime#exec()
.
Process process = Runtime.getRuntime().exec(command);
InputStream stdout = process.getInputStream();
InputStream stderr = process.getErrorStream();
This will return whatever you'd normally see when entering the command plain in command prompt, including errors. Your answer may be in there. Long story short: When Runtime.exec() won't, this is an excellent article explaining its pitfalls in depth. Read all the 4 pages. It contains helpful code snippets.
My guess is that either java
isn't recognized as a command (e.g. missing in %PATH%
), or that it's an user permission issue. At least, that are the most common causes in cases like that.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow