jproc icon indicating copy to clipboard operation
jproc copied to clipboard

What about option for mix stderr and stdout to the same output stream?

Open TimurAditazz opened this issue 8 years ago • 6 comments

TimurAditazz avatar Feb 03 '17 13:02 TimurAditazz

Sounds like an interesting idea. How would you merge the two streams? Always one line at a time?

fleipold avatar Feb 09 '17 09:02 fleipold

I wonder if users expect different behavior than as shell making that redirection. 2>&1

TimurAditazz avatar Feb 09 '17 09:02 TimurAditazz

There are a couple of things, perhaps you would like to specify a prefix for each stream, so that you get something like this:

[stdout] I was printed on stdout
[stderr] I was printed on stderr

You might even want to be able to specify a line prefix and a line suffix per stream, so that you can use ansi sequences, e.g. to turn the stderr stream red.

fleipold avatar Feb 09 '17 09:02 fleipold

Sounds great and gorgeous

TimurAditazz avatar Feb 09 '17 09:02 TimurAditazz

public static String runShellCommand(String shellCommand) {

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        new ProcBuilder("bash")
                .withArgs("-c", shellCommand)
                .withOutputStream(out)
                .withErrorStream(out)
                .withNoTimeout()
                .run();
        return out.toString();
    }

This does the job for me...

Bendodroid avatar Sep 13 '18 13:09 Bendodroid