my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Executing system command and obtaining result in real-time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Executing system command and obtaining result in real-time" Watch "Executing system command and obtaining result in real-time" New topic
Author

Executing system command and obtaining result in real-time

Andy McBee
Greenhorn

Joined: Jul 23, 2009
Posts: 5
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

Joined: Jul 23, 2009
Posts: 5
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

Joined: Oct 13, 2005
Posts: 37941
    
  22
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.
 
 
subject: Executing system command and obtaining result in real-time
 
Similar Threads
I need help refining some code
Problems while executing unix script from Java...
getting input from the command line
How to get a value from process
Compilation of java code at runtime