views:

23

answers:

1

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?

A: 

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.

BalusC
This was very helpful and allowed me to debug the problem. Thank you!
Elliott