If one batch file
CALL
s another batch file CTRL-C will exit both batch scripts.
If CMD /c is used to call one batch file from another then CTRL-C will cause only one of the
batch scripts to terminate. (see also
EXIT
)
Long Commands and long filenames
Under Windows XP, the CMD
command line is limited to
8,191
characters.
For all versions of Windows, NTFS and FAT allows
pathnames
of up to 260 characters.
A workaround for the limited pathname length is to prefix \\?\
for example:
\\?\C:\TEMP\Long_Directory\Long_Filename.txt
ErrorLevel
CMD /C will return an errorlevel, for example
CMD /c dir Z:
where the drive Z: does not
exist, will return %errorlevel% = 1 to the calling CMD shell.
Command Extensions
Much of the functionality of CMD.exe can be disabled - this will affect all the internal commands,
Command Extensions are enabled by default. This is controlled by setting a value in the registry:
HKCU\Software\Microsoft\Command Processor\EnableExtensions Alternatively under Win XP
you can run CMD /e:on or CMD /e:off
Examples
:
Run a program and pass a Filename parameter:
CMD /c write.exe c:\docs\sample.txt
Run a program and pass a Long Filename:
CMD /c write.exe "c:\sample documents\sample.txt"
Spaces in Program Path:
CMD /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""
Spaces in Program Path + parameters:
CMD /c ""c:\Program Files\demo.cmd"" Parameter1 Param2
Spaces in Program Path + parameters with spaces:
CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2
with space""
Launch Demo1 and then Launch Demo2:
CMD /c ""c:\Program Files\demo1.cmd" & "c:\Program Files\demo2.cmd""
“Those who can command themselves, command others” - Hazlitt
COLOR
Sets the default console foreground and background colours.
Syntax
COLOR [
background][
foreground]
Colour attributes are specified by 2 of the following hex digits. Each digit can be any of the
following values:
0 =
Black
8 = Gray
1 = Blue
9 = Light Blue
2 =
Green
A = Light Green
3 = Aqua
B =
Light Aqua
4 = Red
C = Light Red
5 = Purple
D = Light Purple
6 =
Yellow
E = Light Yellow
7 = White
F =
Bright White
If no argument is given, COLOR restores the colour to what it was when CMD.EXE started.
Colour values are assigned in the following order:
The DefaultColor registry value.
The
CMD
/T command line switch
The current colour settings when cmd was launched
The COLOR command sets ERRORLEVEL to 1 if an attempt is
made to execute the COLOR
command with a foreground and background colour that are the same.
Chia sẻ với bạn bè của bạn: