What the question says.
Ultimately what I want is to execute gcc and capture the output if there's an error. The problem is errors are written to stderr instead of stdout. On Linux I can do
gcc foo.c 2>&1
How can I accomplish this on Windows?
What the question says.
Ultimately what I want is to execute gcc and capture the output if there's an error. The problem is errors are written to stderr instead of stdout. On Linux I can do
gcc foo.c 2>&1
How can I accomplish this on Windows?
There is. Simply right click into the console window, select Mark. With your mouse select the desired area and right click. Now you can paste it into a text file with Ctrl-V.
If you need the output of a program into a text file, run it like this:
myprogram.exe > myfile.txt
See here about redirecting:
1. Using command redirection operators
2. Redirecting Error Messages from Command Prompt: STDERR/STDOUT
You can do what you want like this: D:\>dir 1> test.txt 2> testerr.txt
gcc > myfile.txt Why i need to put 2, this way? gcc 2> myfile.txt> redirection is the same as 1> (which is stdout redirection). 2> redirection is stderr redirection. All-in-all, this is exactly the same as in Linux.How do I do the same in Windows? should have been: You do it the same way as in Linux.Richard, your "accepted answer" is too long and it is too wrong.
The short answer to your question (as currently stated in your last sentence: "How can I accomplish this on Windows?") is:
But I'll also give you a long answer.
Your 2>&1 redirection works in a cmd.exe window the same way. I even re-tested it right now, since my cmd.exe experience is a bit rusty. I used this Ghostscript command (intentionally meant to produce output on stdout as well as on stderr):
gswin32c -sDEVICE=nullpage -dFirstPage=12 -dLastPage=11 my-20-page-test.pdf
I got all the expected output into the shell window. Then I did:
gswin32c -sDEVICE=nullpage -dFirstPage=12 -dLastPage=11 my-20-page-test.pdf ^
1>stdout.log
and stderr still printed into the window, but stdout.log had the 'missing' original output. Next I did:
gswin32c -sDEVICE=nullpage -dFirstPage=12 -dLastPage=11 my-20-page-test.pdf ^
2>stderr.log
and stdout now printed into window, while stderr.log had the rest of Ghostscript's messages. Next:
gswin32c -sDEVICE=nullpage -dFirstPage=12 -dLastPage=11 my-20-page-test.pdf ^
1>stdout.log 2>stderr.log
and (as expected): no output in window, all output divided up between stdout.log and stderr.log. Last test:
gswin32c -sDEVICE=nullpage -dFirstPage=12 -dLastPage=11 my-20-page-test.pdf ^
1>all.log 2>&1
and result now:
Which is the same behaviour as stderr/stdout redirection as on Linux.