Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Executing commands on DOS prompt

 
raj NZ
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
What is the easiest way to execute dos command prompts and read back
the return. I have started out on this path.

Runtime r = Runtime.getRuntime();
Process p = r.exec("cmd");
PrintStream out = new PrintStream(p.getOutputStream());
out.println("echo Raj");
out.flush();
out.close();
InputStreamReader in = new InputStreamReade(p.getInputStream());
BufferedReader br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();

Cheers
Raj
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's about it. You may find some commands that hang if you're not also reading errout. To read two streams at once you can run two stream readers on threads. Search this forum for StreamGobbler - there have been samples posted before. The whole thing goes something like:
 
raj NZ
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers is there any way to hide the dos prompt window
while my commands are being run
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!