Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing system command and obtaining result in real-time

 
Andy McBee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's easy to launch some program and then - when this program finishes - get a result (stdout, for instance). I use the following code:

But how can i get stream contents in real time?
Being precise, i have a program that prints a line every n seconds; and i want to launch it from java code and every n seconds process the line it prints.
 
Andy McBee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, i found that problem is somewhere else - this code doesn't print output typically produced by Process.exe - it just exits.

UPD. It does exactly what i need, just a few lines need to be replaced:
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy McBee wrote:It's easy to launch some program . . .
Easy? It is usually complicated, and whenever we see people using Runtime.exec() we tell them to search for when Runtime.exec() won't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic