For example:
The cloud community small weave likes to use the bat. If you run the command automatically at bat and the window closes so that it doesn't see the effect, then we can add
cmd /k echo 云栖社区
You don't have to add pause every time. Because many of the bat's studies will make mistakes in many cases, so we can see the error message.
Starts a new example of the command interpreter Cmd.exe. If used without parameters, CMD will display the operating system version and copyright information.
Grammar
cmd [{/c |/k}] [////////////////////////////////U}] [/T:FG] [/e:{on | off}] [/f:{on | out}] [/v:{on | off}] [String]
Parameters
/C
Executes the command specified by String, stops after execution, and exits. For example:
@echo off
cmd/c "Echo%cd% & Echo ddddd & set xxx=12345"
pause
CLS
The following pause and CLS will also execute, execution to the end will exit the current running environment (double-click to run), but the current environment variable XXX will not be retained (start-> run->cmd, and then execute the current bat file after execution, enter set again to view the current environment variable)
/k
Executes the command specified by String and continues, running to keep the current running window and environment variables. For example:
@echo off
cmd/k "Echo%cd% & Echo ddddd & set xxx=12345"
pause
CLS
After the program executes the command that follows the string after cmd, it suspends execution, so the subsequent pause and CLS do not execute. But window and environment variables will remain. How to run: Double-click or execute the current bat file from the command line
/s
Modify the handling of String after/C or/k.
/q
Turn off Echo.
/d
Disables AutoRun command execution.
/A
The internal command output is formatted as a pipe or file according to the American National Standards Institute (ANSI).
/u
Formats the internal command output as a pipe or file as Unicode.
/t:fg
Sets the foreground F color and background G color. The following table lists valid hexadecimal digits that can be used as F and G values.
|
Value |
Color |
0 |
Black |
1 |
Blue |
2 |
Green |
3 |
Light Green |
4 |
Red |
5 |
Purple |
6 |
Yellow |
7 |
White |
8 |
Grey |
9 |
Light Blue |
A |
Light Green |
B |
Light Light Green |
C |
Light Red |
D |
Light Purple |
E |
Light Yellow |
F |
Bright White |
/e:on
Enable Command extensions.
/e:off
Disables command extensions.
/f:on
Enables file and directory name completion.
/f:off
Disables file and directory name completion.
/v:on
Enables deferred environment variable extensions.
/v:off
Disables the deferred environment variable extension.
String
Specifies the command to execute.
/?
Displays help at the command prompt.
Comments
Using multiple commands
You can use multiple commands separated by a command delimiter && in String, but these commands must be enclosed in quotation marks (for example, "command&& command && Command").
?
Working with quotes
If you specify/C or/k,cmd, the remaining commands in String are processed and the quotation marks are retained only if all of the following conditions are true:
The/s is not used.
The exact use of a pair of quotes.
No special characters are used in quotation marks (for example,:&<> () @ ^ |).
One or more white-space characters are used within quotation marks.
The String within the quotation marks is the name of the executable file.
If the above conditions are not met, then the first character of the String is checked first to verify that it is a left quotation mark. If the first character is a left quotation mark, it is separated from the closing quotation mark. Any text that follows the closing quotation marks is preserved.
Execute registry subkey
If/d is not specified in String, Cmd.exe looks for the following registry subkey:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command PROCESSOR\AUTORUN\REG_SZ
HKEY_CURRENT_USER\Software\Microsoft\Command PROCESSOR\AUTORUN\REG_EXPAND_SZ
If one of these registry subkeys or two are present, they are executed before all other variables are executed.
Warning
Improper editing of the registry can severely damage your system. Before you change the registry, you should back up any valuable data on your computer.
Enabling and Disabling command extensions
In Windows XP, command Extensions are enabled by default. For specific processes, you can use/e:off to disable them. You can enable or disable extensions for all cmd command-line options on your computer or in a user's session by setting the following REG_DWORD values:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\enableextensions\reg_dword
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\enableextensions\reg_dword
Use Regedit.exe in the registry to set the REG_DWORD value to 0x1 (that is, enabled) or 0x0 (that is, disabled). User-specific settings take precedence over computer settings, and command line options take precedence over registry settings.
Warning
Improper editing of the registry can severely damage your system. Before you change the registry, you should back up any valuable data on your computer.
When command extensions are enabled, the following commands are affected:
? |
Assoc |
? |
Call |
? |
ChDir (CD) |
? |
Color |
? |
Del (Erase) |
? |
Endlocal |
? |
For |
? |
Ftype |
? |
Goto |
? |
If |
? |
MKDIR (MD) |
? |
popd |
? |
Prompt |
? |
pushd |
? |
Set |
? |
Setlocal |
? |
Shift |
? |
Start (also includes changes to external command procedures) |
For more information about these commands, see Related Topics.
Enabling deferred environment variable extensions
If you enable deferred environment variable extensions, you can use the exclamation characters to override the Run-time environment variable values.
Enable file and directory name completion
By default, file and directory name completion is disabled. For specific cmd command processing, you can enable or disable file name completion through/f:{on|off. You can enable or disable file and directory names that are processed by all CMD commands on your computer or in a user logon session by setting the following REG_DWORD values:
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\completionchar\reg_dword
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\pathcompletionchar\reg_dword
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\completionchar\reg_dword
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\pathcompletionchar\reg_dword
To set the REG_DWORD value, run Regedit.exe and use the hexadecimal value of the control character for the specific feature (for example, the Tab key is represented by 0x9, and the BackSpace key is represented by 0x08). User-specific settings take precedence over computer settings, and command line options take precedence over registry settings.
Warning
Improper editing of the registry can severely damage your system. Before you change the registry, you should back up any valuable data on your computer.
If you have enabled file and directory name completion with/f:on, you can use Ctrl+d for the directory name, and ctrl+f for the file name completion. To disable a specific completion character in the registry, use the value of the space [0x20], because the space is not a valid control character.
When you press Ctrl+d or ctrl+f, cmd processes the file and directory names to complete the operation. The key combinations are to append a wildcard character (if not used) after a String, create a matching list of paths, and then display the first matching path. If all paths do not match, the file and directory name completion will emit a warning sound and do not change the displayed content. To view the paths in the matching path list individually, press Ctrl+d or ctrl+f repeatedly. To view the list backwards, press Ctrl+d or ctrl+f while pressing Shift. To discard a saved list of matching paths and generate a new list, you can edit the String and press Ctrl+d or CTRL+F. If you switch between Ctrl+d and Ctrl+f, the saved list of matching paths is discarded and a new list is generated. The only difference between a ctrl+d key and a ctrl+f combination is that ctrl+d matches only the directory name, and ctrl+f matches both the file name and the directory name. If you use file and directory names in any internal directory command (that is, CD, MD, or RD), you will use only the directory to complete.
If you enclose a matching path in quotation marks, the completion of file and directory names will correctly handle file names that contain spaces or special characters.
The following special characters need to be quoted:& < > [] {} ^ =;! ' +, ' ~ [space]
If the information provided contains spaces, enclose the text in quotation marks (for example, "Computer name").
If a file and directory name is processed from within a string, then [Path] is discarded in any part of the right side of the cursor (that is, the location in string that handles the completion of the operation).