C:\_G\WWW\~ELISANET\INFO\tscmd082.html
<http://www.elisanet.fi/tsalmi/info/tscmd082.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Sat 27-Oct-2018 20:56:25

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

This page is edited from the 1cmdfaq.txt faq-file contained in my tscmd.zip command line interface (CLI) collection. That zipped file has much additional material, including a number of detached .cmd script files. It is recommended that you also get the zipped version as a companion.

Please see "The Description and the Index page" for the conditions of usage and other such information.



82} Why does echo 9>temp.txt fail while echo 10>temp.txt works?

A cmd.exe feature. The sole digit nine is taken to be a file handle 0-9 when redirection is used. You'll have to escape it e.g. applying
  @echo off
  echo ^9>temp.txt
or
  echo.9>temp.txt
or
  >temp.txt echo 9
or
  (echo 9)>temp.txt

The problem might be particularly insidious in a case like this (also see item #86).
  @echo off & setlocal enableextensions
  set var_=9
  echo %var_%>tmp$$$.txt
  for %%c in (type del) do call %%c tmp$$$.txt
  endlocal & goto :EOF

The output will be
  C:\_D\TEST>cmdfaq
  ECHO is off.

That can be avoided by using
  echo ^%var_%>tmp$$$.txt
or
  echo.%var_%>tmp$$$.txt
or
  >tmp$$$.txt echo %var_%
or
  (echo %var_%)>tmp$$$.txt

What does one do with a file handle? Try this without having a diskette in the drive
  @echo off
  dir a: > temp.dir

What you'll get is on the screen
  The device is not ready.

But if you would rather that the line went into the temp.dir file, then
  @echo off
  dir a:> temp.dir 2>&1

References/Comments:
  Windows Commands

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd082.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd082
http://www.elisanet.fi/tsalmi/info/tscmd082.html
file:///c:/_g/www/~elisanet/info/tscmd082.html