0

I want to run a C program in mintty and divert the stderr output stream to a file, debug.txt. This may be accomplished using:

./zombie_jump 2>debug.txt

However, I am having issues lauching this from the Windows command line.

mintty -s 70,55 ./zombie_jump 2>debug.txt

behaves as if the 2>debug.txt was left off the command (running the program but not diverting the error stream), and

mintty -s 70,55 "./zombie_jump 2>debug.txt"

behaves as if I sent "./zombie_jump 2>debug.txt", producing the error Failed to run ./zombie_jump 2>debug.txt: No such file or directory.

What command should I be using?

Edit:

mintty -s 70,55 './zombie_jump 2>debug.txt'

returns Failed to run ./zombie_jump : No such file or directory and creates a file called debug.txt'.

3
  • The problem seems to be that mintty wants separate parameters for the command it runs, so you need to quote the redirection. Without quotes the redirection applies to mintty itself, which I guess sets up new standard I/O paths. If you include the redirection in the same quotes as the command, then this becomes the whole command, looking for a single name with embedded blank and redirection characters. Single quotes have no special meaning in cmd, hence your last finding.
    – AFH
    Apr 16 '16 at 17:29
  • Two suggestions: mintty -s 70,55 ./zombie_jump "2>debug.txt" to stop the redirection in cmd; if this fails create ./zombie_noerrs containing ./zombie_jump 2>debug.txt and run mintty -s 70,55 ./zombie_noerrs.
    – AFH
    Apr 16 '16 at 17:30
  • Unfortunately the first suggestion doesn't work, same result as my second attempt above. The second isn't optimal either, as I'm trying to find a command I can use with Sublime Text 2 to run the current file I'm working on.
    – Dimpl
    Apr 17 '16 at 2:06
1

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.

1
  • Thank you very much for the detail, this is an excellent answer. When I tried bash (chat.stackexchange.com/rooms/38465/…), I was missing the -c option, so received no such file or directory and cannot execute binary file errors.
    – Dimpl
    Apr 17 '16 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.