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