The error here is quite easy to understand: mintty
doesn’t forward your programs output to (presumably) cmd
, where the output redirection is set up. Instead, it displays output in its own GUI window. That’s what a terminal emulator is designed to do, after all. :)
Output redirection is a shell feature. If you just run mintty my_command
, you’re not using a shell at all. Instead, mintty
directly launches my_command
.
If you quote "my_command 2>out.err"
, you’re telling mintty
to look for a command of that (whole) name. It is equivalent to typing "my_command 2>out.err"
in a regular Linux shell. Won’t work either way.
So now that we’ve established it’s a shell feature, it’s clear we need a shell. A common choice would be Bash. Bash can be passed a command string to execute when it starts, like this:
bash -c "my_command 2>out.err"
That means we can use it like this with mintty
:
mintty /bin/bash -c "my_command 2>out.err"
On my machine, the Cygwin Bash shell launched this way inherits the working directory I have in cmd
.