• Post Reply Bookmark Topic Watch Topic
  • New Topic

read lines from Writer write method  RSS feed

 
pete reisinger
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using one class that prints the output using Writer's write method.
How can I read the output?

I tried:


but this doesn't work
 
Swastik Dey
Rancher
Posts: 1782
14
Android Eclipse IDE Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, whats the issue here? The code should get the input from console.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that once data is written to the console, it's gone. There's no way to get it back.
If you want the output to go to two places, replace the Java standard out with an output class that emulates tee. One end of the tee can go to the "real" standard out, the other to a buffer that saves the output for later reading.
 
pete reisinger
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I include the code for reading input, it just stops working, looks like it is waiting for user's input and it doesn't read what's printed by Writer class.
The problem is that the class (jar file) I'm using is compiled and I don't have source code, so I cannot just change methods.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about piping the output of the app you can't change into the standard input of your app?
IO Redirection
 
pete reisinger
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you post how to do that please?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pete reisinger wrote:could you post how to do that please?


Did you miss the link marked "IO Redirection" in my post?
Your app then reads from standard input.
 
pete reisinger
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It says how to pipe output on command line, but how do I pipe output in java?
Thanks.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you cannot change the first application, your next best bet is to pipe the application's output into your application.
It doesn't matter what the application is written in. The command line syntax for IO redirection is the same.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!