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
entered:
type test.txt
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.
See also:
file: /Techref/os/win/winnt/slide25.htm, 2KB, , updated: 2011/3/14 16:12, local time: 2024/11/8 16:58,
3.12.163.105:LOG IN ©2024 PLEASE DON'T RIP! THIS SITE CLOSES OCT 28, 2024 SO LONG AND THANKS FOR ALL THE FISH!
|
©2024 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://techref.massmind.org/techref/os/win/winnt/slide25.htm"> Help for all NT Version 4.0 commands</A> |
Did you find what you needed? |
Welcome to massmind.org! |
The Backwoods Guide to Computer Lingo |
.