• Post Reply Bookmark Topic Watch Topic
  • New Topic

read stdout of an executable ran on the command line

 
Diego Bowen
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Computer Folks,
I was just wondering if I might be able to read the standard output of an executable?? Something similar to piping the output and grep'ing it for a string or to....Can I do this in Java???
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By standard output, do you mean to the console? Are these both Java applications?
There are PipedInput and PipedOutput streams, but not sure how you are wanting to hook those out to the exe output.
 
Diego Bowen
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>By standard output, do you mean to the console? Are these both Java > >applications?
>There are PipedInput and PipedOutput streams, but not sure how you are wanting >to hook those out to the exe output.
Yes to the console...
No only the application doing the listening of stdout is in java...
Basically I want to parse the stdout output of non-java exec and send it a UI as a type of real-time status of a run.
Thanks
 
Ouaknin lionel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try

be aware that this code does not work with all platform and all processes. typically on my Win 98 computer it doesn't work. But it will work on unix.
[ September 17, 2003: Message edited by: Ouaknin lionel ]
[ September 17, 2003: Message edited by: Ouaknin lionel ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can connect your Java program to the stdin, stdout and errout of the program you're running as shown above. You talked about capturing ongoing status of the running command. You may want to hook your readers to the stdout and errout on their own threads so your program can continue working while the command is running. Here is a Remote Command Server that I did. It's not bug-free and it's a lot more complicated than what you need, but the command server and stream readers might give you some good ideas.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!