Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Viewing console output of exec right away
Viewing console output of exec right away [message #327050] Mon, 07 April 2008 16:47 Go to next message
Eclipse UserFriend
Originally posted by: ups_genius.gmx.net

Hi everyone!

I am pulling my hair our over this problem, I hope somebody can help me, I
just can't get the right idea how to do it.

I would like to write the output of a batch file executed via
Runtime.getRuntime().exec(cmd); to the console. This alone is not the
problem. I manage to write the output to the console whenever the batch
file execution is finished. But since this takes quite a while and the
file produces quite a bit of output, I would like to send the output to
the console right away, whenever it is produced.
I tried created the following class for the stdout and stderr threads, but
the console content only changes whenever the batch is finished and the
console then suddenly contains the complete content.
The "System.out.println" in the line below though does the job correctly,
writing line by line.
Can anyone help me? What am I doing wrong?

Thank you very much!

Christian


// Console for stderr and stdout
MessageConsole console = findConsole("Batch Output");
//out = console.newMessageStream();
MessageConsoleStream stream = console.newMessageStream();


// any error message?
StreamReader errorReader = new StreamReader(proc.getErrorStream(), stream);

// Handle input (java plugin input == batch file output)
StreamReader outputReader = new StreamReader(proc.getInputStream(),
stream);



class StreamReader extends Thread
{
InputStream is;
String type;
MessageConsoleStream stream;

StreamReader(InputStream is, MessageConsoleStream stream)
{
this.is = is;
this.stream = stream;
}

public void run()
{
try
{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;

while ( (line = br.readLine()) != null)
{
stream.println(line);
System.out.println(line);
}
br.close();

}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
Re: Viewing console output of exec right away [message #327055 is a reply to message #327050] Mon, 07 April 2008 20:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

"Christian" <ups_genius@gmx.net> wrote in message
news:026dec537341a4689486383c407b2757$1@www.eclipse.org...
> Hi everyone!
>
> I am pulling my hair our over this problem, I hope somebody can help me, I
> just can't get the right idea how to do it.
>
> I would like to write the output of a batch file executed via
> Runtime.getRuntime().exec(cmd); to the console. This alone is not the
> problem. I manage to write the output to the console whenever the batch
> file execution is finished. But since this takes quite a while and the
> file produces quite a bit of output, I would like to send the output to
> the console right away, whenever it is produced.
> I tried created the following class for the stdout and stderr threads, but
> the console content only changes whenever the batch is finished and the
> console then suddenly contains the complete content.
> The "System.out.println" in the line below though does the job correctly,
> writing line by line.
> Can anyone help me? What am I doing wrong?
>
> Thank you very much!
>
> Christian
>
>
> // Console for stderr and stdout
> MessageConsole console = findConsole("Batch Output");
> //out = console.newMessageStream();
> MessageConsoleStream stream = console.newMessageStream();
>
>
> // any error message?
> StreamReader errorReader = new StreamReader(proc.getErrorStream(),
stream);
>
> // Handle input (java plugin input == batch file output)
> StreamReader outputReader = new StreamReader(proc.getInputStream(),
> stream);
>
>
>
> class StreamReader extends Thread
> {
> InputStream is;
> String type;
> MessageConsoleStream stream;
>
> StreamReader(InputStream is, MessageConsoleStream stream)
> {
> this.is = is;
> this.stream = stream;
> }
>
> public void run()
> {
> try
> {
> InputStreamReader isr = new InputStreamReader(is);
> BufferedReader br = new BufferedReader(isr);
> String line = null;
>
> while ( (line = br.readLine()) != null)
> {
> stream.println(line);
> System.out.println(line);
> }
> br.close();
>
> }
> catch (IOException ioe)
> {
> ioe.printStackTrace();
> }
> }
> }
>

Have you tried adding a stream.flush() after the stream.println. If the
OutputStream is buffered, you need to flush the stream in order to force the
data out.
Re: Viewing console output of exec right away [message #327059 is a reply to message #327055] Tue, 08 April 2008 06:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ups_genius.gmx.net

True, the stream should be flushed. Unfortunately that does not make any
difference...
Re: Viewing console output of exec right away [message #327088 is a reply to message #327059] Wed, 09 April 2008 11:02 Go to previous message
Eclipse UserFriend
Originally posted by: ups_genius.gmx.net

Hi again!

I tried several other options, but just can't get it to work. Any help
would be very welcome.

Thanks in advance!
Christian
Previous Topic:How to detect key state when clicking a table column
Next Topic:FileSystemImportWizard: Problem Openeing Wizard
Goto Forum:
  


Current Time: Thu Dec 26 22:04:44 GMT 2024

Powered by FUDForum. Page generated in 0.04726 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top