• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

redirect conosle result

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai
how to redirect the console result to a application.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One neat way is to run the command with runtime.exec and connect readers to the stdout and errout of the command. You can also connect a writer to the stdin of the program and interact with prompts and responses and such. You kinda need to get into some threading tricks to make it all work, so it's not quite a trivial task. Let us know if you'd like samples.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ October 05, 2004: Message edited by: Stefan Wagner ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to capture the output of a process that I started using exec(), and I have observed a different behaviour between stdin and stderr.

I have de following C code: (HelloWorld.c)

and to capture output: (TheLaucher.java)


In this case I have to wait till the end of the process to get the output but if I use the stderr changing:


for


I get the strings as they are available.
How can I get the same behaviour with the stdout, i.e. to get all the messages as they are produced? Why are they different?

Thanks

Joaquin Morcate
[ November 17, 2005: Message edited by: Joaquin Morcate ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Processes can output to 2 distinct streams, stdout and stderr. While you see these two as one in a command box, they are still distinct. When reading one, you will not see the results of the other.

There are ways to redirect them, so that they both go to the same stream:
- in Java, use System.setOut(System.err) or System.setErr(System.out).
- if that is not possible, you can use OS redirection. After your command you add a 2>&1 to redirect the error stream to the output stream and >&2 for the other way around. E.g, "someCommand -paramater value <any other input to the command here> 2>&1". There cannot be any spaces around the >.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic