You are not logged in.

#1 24 May 2014 12:00

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 251
Website

[Undocumented] cmd.exe and XCOPY.EXE

Hello. I found a undocumented compatibility feature of cmd.exe

On msdos when you use xcopy and the destination file exist it ask for overwrite or not. Edit: penpen says that in old msdos xcopy overwrite without ask.
On windows nt days xcopy by default prompt for overwrite or not, unless you specify the /Y option in the command line or in the COPYCMD variable. But if cmd.exe found a XCOPY.EXE (uppercase) automatically create or append the option /Y to the COPYCMD variable. Summary:

if you run xcopy and cmd.exe found this:

xcopy.exe : Normal feature. If options /Y is not specified on command line or COPYCMD variable, ask for overwrite or not.
XCOPY.EXE: Compatibility feature. Append or create the COPYCMD with /Y, overwrite silencely if you not specify /-Y on command line.

Look this example:

@echo off
rem When cmd.exe call xcopy and the located executable have a uppercase filename (XCOPY.EXE)
rem momentaneously it create or append the COPYCMD enviroment variable with this:" /Y" (without quotes)
rem then when xcopy.exe is executed it will consider the option /Y present
rem and a overwriting of files without ask will do.
rem after the execution of xcopy.exe cmd will restore the previous content of the COPYCMD variable.
rem Feature only on batch script mode, not interactive mode.

echo hello>f.txt
echo bye>g.txt

echo Normal feature. Please reply No
xcopy f.txt g.txt

echo Content of g.txt:
type g.txt

pause
echo Undocumented compatibility feature

rem copy xcopy.exe as uppercase: XCOPY.EXE
copy %windir%\system32\xcopy.exe XCOPY.EXE >Nul
xcopy f.txt g.txt

echo Content of g.txt:
type g.txt

del XCOPY.EXE

pause

Last edited by carlos (26 May 2014 19:38)

Offline

Board footer

Powered by