Brad,
Here are the results of executing your jar file on my Mac. I ran a 3rd test case where I redirect stderr to stdout in the native shell. (echo “java -jar testapp.jar 2>&1” | run > brad.txt). After each test, I cat the file so you can see what was captured and what was printed on the screen.
Here are the results.
`
`
`
/* WITH redirectErrorStream(true) (without the changes in my pull request) */
`
`
`
`
/*here, we see the output of both streams printed to the screen. */
`
`
CommandBox:webroots> !java -jar testapp.jar
`
`
bash: no job control in this shell
`
`
This is the out stream
`
`
This is the error stream
`
`
/I didn’t bother showing the content of the brad.txt file after the above command./
`
`
`
`
/*now we redirect to brad.txt. */
`
`
CommandBox:webroots> echo “java -jar testapp.jar” | run > brad.txt
`
`
/above command didn’t print either stream to the console./
`
`
/*and both streams ended up in the txt file: */
`
`
CommandBox:webroots> cat brad.txt
`
`
bash: no job control in this shell
`
`
This is the out stream
`
`
This is the error stream
`
`
`
`
/*what if we redirect stderr to stdout in our native shell, bash? */
`
`
CommandBox:webroots> echo “java -jar testapp.jar 2>&1” | run > brad.txt
`
/*above command didn't print either stream to the console.*/
/*and both streams ended up in the txt file: */
`
CommandBox:webroots> cat brad.txt
`
`
bash: no job control in this shell
`
`
This is the out stream
`
`
This is the error stream
`
`
`
/*round 1 tests complete! It seems the last two tests in this round did the exact same thing. Nothing printed to console and both streams captured in text file. */
`
`
/* Now we will apply the change in my pull request and run the same tests again */
`
/* WITH redirectError(REDIRECT.inherit): */
`
`
`
`
CommandBox:webroots> r
`
`
`
`
Reloading shell…
`
`
/*here, we see the output of both streams printed to the screen. */
`
`
CommandBox:webroots> !java -jar testapp.jar
`
`
This is the error stream
`
`
This is the out stream
`
`
`
`
/the next command prints the stderr stream to the console:/
`
`
CommandBox:webroots> echo “java -jar testapp.jar” | run > brad.txt
`
`
This is the error stream
`
`
`
`
/and the stdout stream was redirected to our txt file:/
`
`
CommandBox:webroots> cat brad.txt
`
`
This is the out stream
`
`
`
`
/and the 3rd test case, redirect stderr from bash and stdout in commandBox prints nothing in the console:/
`
`
CommandBox:webroots> echo “java -jar testapp.jar 2>&1” | run > brad.txt
`
`
`
`
/and now both streams are redirected to our txt file:/
`
`
CommandBox:webroots> cat brad.txt
`
`
This is the out stream
`
`
This is the error stream
`
`
`
Besides making the bash shell interactive (which removes the “no job control” nag and includes some additional “benefits” that may or may not apply when running native shell commands from commandBox), the change in my pull request seems to provide a bit more flexibility when redirecting stderr. It also more closely matches the way the bash shell natively handles the stderr stream when you redirect to a file. That is, stderr is printed on the screen while stdout is redirected to the file. In bash, if you want both streams captured in a file, you would do something like, ‘some command 1>some_file 2>1’. Then, you will get nothing printed on the screen and both streams in some_file.
Without my pull request, stderr will always get redirected when you redirect stdout, which may be exactly what you are going for. But, this behavior may surprise some people because when you execute ‘some_command > some_file’ , what you are really doing is ‘some_command 1>some_file’. (redirecting stdout, or stream “1”, to a file)
So the question is, do you want redirection to a file to behave more like the native shell’s redirection, or do you intentionally want to redirect both streams (stderr and stdout) at the same time?
–Joel