views:

87

answers:

3

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?

+5  A: 

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

PeterK
Yes! But not manually ... And yes, automatically.
Richard
+1 Didn't know I could do that
NullUserException
I tried that. But, at the command prompt, the output to appear ... But the output is not displayed when pointing to a text file.
Richard
your program/script will have to get that info from the text file. There is a util somewhere called 'tee' that redirects stdout to a file while still showing it on the console.
Kelly French
Yeah, is it. Thanks... How its works? Why i can't get the output just with:`gcc > myfile.txt`Why i need to put 2, this way? gcc 2> myfile.txt
Richard
@Richard: `>` 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.
pipitas
@all: I'm puzzled this answer got so many upvotes. The correct and short answer to question `How do I do the same in Windows?` should have been: `You do it the same way as in Linux.`
pipitas
A: 

If you want the output of a particular command, there's a simple way to push console output to a file.

Here's a trivial example using the 'dir' command (the leading > represents your prompt):

>dir > diroutput.txt

djacobson
+3  A: 
pipitas
To be fair, the question looks like that because I edited it. On the other hand, [this](http://stackoverflow.com/posts/3460370/revisions) is what it looked like before I did it.
NullUserException