Separate standard output from standard error when running a program in Eclipse

eclipse, io-redirection

Solution

Can you try to redirect your stream stdout to a custom View with a SWT Text in it, leaving stderr to the default console. See this thread

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;


import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;


public class ConsumeSysout {


    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        final Text text = new Text(shell, SWT.NONE);
        shell.open();


        OutputStream out = new OutputStream() {
            @Override
            public void write(int b) throws IOException {
               text.append(Character.toString((char) b));
            }
        };
        System.setOut(new PrintStream(out));


        System.out.println("Hello World!");


        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

Problem

I am debugging a Java program in Eclipse. This program normally writes binary data to its standard output, but it can write error messages and stack traces to its standard error stream. I would like to redirect the binary data to a file, while continuing to show the standard error output in a console. This is trivial when running from the command line. Is it possible under Eclipse? So far I have only figured out how to redirect both standard output and standard error to the same file. I cannot see a way to separate the two other than adding a new command-line option to the program. Related: I/O redirection in Eclipse?

Original source