Displays messages, or turns command-echoing on or off. ECHO [ON | OFF] ECHO [message] Type ECHO without parameters to display the current echo setting.
This little tidbit applies to XP, Vista, 2k8, and probably Windows 7 but I've never, in years and years of doing this seen it documented (as an error) or seen the workaround.
Try this command at the prompt:
echo test 2>test.txt
One might expect to see nothing on the console and then if you
you might expect to see "test 2"
In fact, you see "test" on the console right after the echo and text.txt is empty!
What happened? The 2> is redirecting any error messages from echo test to the file test.txt. It is being interpreted as a stderr redirect and that leaves no > to send "test" into the file. Experienced programmers won't be shocked by that.
Now, how to avoid it? LOL this one is what surprised me:
(echo test 2)>test.txt
Can you believe it? That actually works! So the moral of the story is that if you are going to be echoing things to a file, you should probably enclose all of those echo commands in parenthesis as a habit.
It turns out that:
>test.txt echo test 2
is also a valid workaround since the parser takes the file name after the > and then goes back to interpreting commands.
Adding a space after the 2 or adding quotes is not really a valid workaround as that changes (and limits) the text that can be echoed.
|file: /Techref/os/win/winnt/slide25.htm, 2KB, , updated: 2011/3/14 17:12, local time: 2023/6/7 09:45,
|©2023 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.sxlist.com/techref/os/win/winnt/slide25.htm"> Help for all NT Version 4.0 commands</A>
|Did you find what you needed?|
Welcome to sxlist.com!
& kind contributors
just like you!
Please don't rip/copy
Copies of the site on CD
are available at minimal cost.
Welcome to www.sxlist.com!