What about option for mix stderr and stdout to the same output stream?
Sounds like an interesting idea. How would you merge the two streams? Always one line at a time?
I wonder if users expect different behavior than as shell making that redirection. 2>&1
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.
Sounds great and gorgeous
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...