Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
What is 72162? –  jsalonen Nov 7 '12 at 18:40
    
That was a typo... –  Mikhail Nov 7 '12 at 18:44
    
Possible duplicate of superuser.com/questions/99066/… –  Oliver Salzburg Nov 7 '12 at 21:16
add comment

2 Answers

up vote 6 down vote accepted

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.

share|improve this answer
    
It works on Gentoo and SLES. It might not be very strict POSIX. –  Mikhail Nov 7 '12 at 18:47
2  
    
@OliverSalzburg Haven't known about it. Thanks! –  Alexey Ivanov Nov 7 '12 at 19:25
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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