• Post Reply Bookmark Topic Watch Topic
  • New Topic

getRuntime().exec() issue  RSS feed

 
howie jao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a code which use getRuntime().exec() to open the cmd and input a command string and output the expected result.
String line;
OutputStream stdin = null;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("cmd.exe");
stdin = p.getOutputStream();
line = "some command string";
stdin.write(line.getBytes());
...

The code runs fine. It will open the cmd and type the command string. However this command string will return something when I manually type on the cmd. But when I use in this way, the cmd freeze. It looked like it's waiting for something . Can anyone give me some suggestion ? Why is this happening ?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you handling the input stream as well? See this article for details on all the things that can go wrong.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!