Windows – How to capture shell output to text file

command linewindows 8

In linux I can type in echo "hello" >& text.output and get text output in a file.

How can I get this kind of output in Windows 8?

Is there a way to tell error from output?

My motivation is trying to log the output of tracert and investigate difference between Windows 8 and Windows 7.

Best Answer

The same way as in Linux:

echo "Hello" >text.output

Errors usually printed to stderr stream (it is #2). You can capture stderr stream:

del 1.txt 2>text.output

If the file 1.txt does not exist, text.output will contain Could not find 1.txt.


You can redirect stdout to stderr:

echo "Hello" 2>&1

Or stderr to stdout:

echo "Hello" 1>&2

P.S. I'm not sure your command would work in Linux. Anyway echo "hello" >& text.output generates a syntax error: >& was unexpected at this time.

Related Question