4

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.

3

2 Answers 2

6

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.

3
3

The shell in Windows now is very similar with BASH on Linux. So you can just do

echo "Hello" > text.txt

Or, run your program, and let the system output write to text.txt:

run_program > text.txt

If you need to track the error, use the following:

run_program 2> error.txt

More information and examples could be found here. I/O Redirection

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .