Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Special symbols in DOS


May 23, 2021 DOS Command learning manual




Use conditional processing symbols to run multiple commands from a single command line or script. W hen multiple commands are run through a conditional processing symbol, the command to the right of the conditional processing symbol functions according to the command results to the left of the conditional processing symbol. F or example, you might need to run a new command only if the previous command fails. Alternatively, you may need to run a new command only if the previous command succeeds.

You can use the special characters listed in the following table to pass multiple commands.

Character syntax definition

Command1 and command2 are used to separate multiple commands from a command line. Cmd .exe run the first command, and then run the second command.

Command1 and command2 are used to run commands after the symbol only if the previous command succeeds. Cmd .exe run the first command, and then run the second command only if the first command runs successfully.

|| [ ...] c ommand1 || c ommand2 is only available in || T he previous command is used to run the symbol || t he command that follows. Cmd .exe run the first command, and then run the second command only if the first command fails to run successfully (an error code greater than zero is received).

( ) [...] (command1 and command2) is used to group or nest multiple commands.

; O r, command1 parameter1; parameter2 is used to separate command parameters.

Attention

· T he "and" symbols (and), the pipe symbols (|), and parentheses () are special characters that must be preceded by escape characters (') or quotation marks when passing them as arguments.

· If a command successfully completes the operation, the command returns zero (0) exit code or no exit code



Create a file

Append to a file

The prefix character. I ndicates that the bank does not display in the cmd at the time of execution, and the display can be turned off using echo off

The leading characters for special symbols . T he first just shows aaa's second output file bbb

echo 123456 ^> aaa

echo 1231231 > bbb

() Contains commands

(echo aa & echo bb)

, the default separation symbol like a space.

; A comment, which is followed by a comment

: The effect of the label

Pipeline operation

; S ymbols can be used with different targets when the commands are the same; I solated but the effect remains the same. If an error occurs during execution, only the error report is returned but the program continues to execute


First of all, it is not a command, but a special marker for the DOS batch, which is only used to mask command line echo. Here are some special markers that you might see on the DOS command line or in a batch:

CR (0D) command line end character

Escape (1B) ANSI escape character guide

Space (20) is a commonly used parameter definer

Tab(09) ; - Not commonly used parameter definers

The COPY command file connector

* ? File wildcard

The "" string definer

| The command pipe character

File redirector

The command line echo mask

/ Parameter switch guide

: Batch label guide

% batch variable guide



Second, :: can indeed play the role of rem comments, and more concise and effective; But there are two things to note:

First, in addition to :: any line of characters beginning with : is treated as a label in the batch, and ignores everything that follows directly, just to distinguish itself from the normal label, it is recommended to use a label that goto cannot recognize, that is, a special symbol immediately after: followed by a non-alphanumeric number.

Second, unlike rem, :: after the character line does not echo when executed, whether or not to open the command line echo state with echo on, because the command interpreter does not consider him to be a valid command line, from this point of view, rem in some cases will be more applicable than:: In addition, rem can be used in config .sys files.




You can also use the following:

if exist command

Device refers to a device that is loaded in a DOS system and is usually:

AUX, PRN, CON, NUL

COM1, COM2, COM3, COM4

LPT1, LPT2, LPT3, LPT4

XMSXXXX0, EMMXXXX0

A: B: C: ...,

CLOCK$, CONFIG$, DblBuff$, IFS$HLP$

The specific content will vary slightly depending on the hardware environment, and the following three points need to be guaranteed when using these device names:

1. The device does exist (except for devices virtually by software)

2. The device driver is loaded (standard devices such as aux, prn, etc. are defined by system default)

3. The device is ready (mainly a: b: ..., com1..., lpt1...) etc.)

You can use the command mem/d | Find "device" /i to review the devices loaded in your system

In addition, in THE DOS system, the device is also considered to be a special file, and the file can also be called a character device; Because devices and files are managed using handles, handles are names, similar to file names, except that handles are not applied to disk management, but to memory management, so-called device loading also refers to assigning referenceable handles to them in memory.