开发者

Runtime.getRuntime().exec problem win serv 2003 versus win serv 2008

开发者 https://www.devze.com 2023-01-18 16:02 出处:网络
I have some java code as follows: try { String outString =\"java -jar C:\\\\ami\\\\bin\\\\ImmediateSubmit.jar 12345 localhost\";

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 ser开发者_运维知识库v 2008.

Any ideas why?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号