2

When executing

echo 0 > test.txt

in cmd.exe, the output in test.txt is

0_

where _ means space. Why is there a space appended? Any way to prevent the appending of the space? Thanks!

stefan.at.wpf
  • 15,045
  • 33
  • 131
  • 226
  • 1
    possible duplicate of [How to echo "2" (no quotes) to a file, from a batch script?](http://stackoverflow.com/questions/7225630/how-to-echo-2-no-quotes-to-a-file-from-a-batch-script) – Raymond Chen Mar 26 '12 at 16:52
  • Yes, however from the title one wouldn't expect it's the same. – stefan.at.wpf Mar 28 '12 at 21:04

1 Answers1

8

The space that gets appended is the space between the "0" and the ">" in your command line. There is a non-obvious way to get rid of it: prepend the redirection to the command instead:

>test.txt echo 0
Jon
  • 413,451
  • 75
  • 717
  • 787