please dont rip this site
previous | start | next


ECHO

Displays messages, or turns command-echoing on or off.

  ECHO [ON | OFF]
  ECHO [message]

Type ECHO without parameters to display the current echo setting.

Back to the top of this page

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:



previous | start | next

file: /Techref/os/win/winnt/slide25.htm, 2KB, , updated: 2011/3/14 16:12, local time: 2024/11/25 05:18,
TOP NEW HELP FIND: 
18.224.53.246:LOG IN

 ©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?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/techref/os/win/winnt/slide25.htm"> Help for all NT Version 4.0 commands</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .