Home arrow static arrow Java Programming [Archive] - Is there a way to read from standard output
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Is there a way to read from standard output
This topic has 3 replies on 1 page.

Posts:56
Registered: 9/12/99
Is there a way to read from standard output  
Jul 14, 2004 5:40 PM



 
Folks:

For example, HelloWorld.java prints out "Hello World" to standard output (screen display) . How can I write another java program to capture the output "Hello World" after HelloWorld.java is executed? I just don't want to use a temp file to store the data.

Can somebody provide me couple lines of code as a hint?

Thanks a lot !!!
 

Posts:49
Registered: 6/23/04
Re: Is there a way to read from standard output  
Jul 14, 2004 6:07 PM (reply 1 of 3)



 
Try a pipe. Like this:
java progr1 | java progr2
 

Posts:10,967
Registered: 4/7/01
Re: Is there a way to read from standard output  
Jul 14, 2004 10:32 PM (reply 2 of 3)



 
Capturing the output "Hello World" after HelloWorld.java is executed requires that the output be placed in some sort of vessel at the time of writing; it then can be retrived as long as the vessel contains the data. A file is the most permanent; strings and byte arrays, etc are more tenuous; pipes ae more so. By using java.lang.System.setOut(PrintStream out) to reassign the "standard" output stream, it can be directed at whatever vessel you want.
 

Posts:392
Registered: 3/7/03
Re: Is there a way to read from standard output  
Jul 14, 2004 10:34 PM (reply 3 of 3)



 
http://java.sun.com/developer/TechTips/1999/tt1021.html

may be this will help
 
This topic has 3 replies on 1 page.