DOS symbols and related examples

Source: Internet
Author: User
Tags echo message

The General symbols are used for a moment. Let's take a look. Actually, there are some symbols in the forum ....

Your question is related to two factors:

1.% is an escape character. It is usually translated as an escape character, but it also has a more vivid escape character or escape character. That is to say, % not only escapes and replaces the relevant specific string with a specific string, but also is "de-escaped ". Similar to the Escape Character "/" in C language, double % will escape and escape as single %, and four % will escape as double %.

2. For itself is a special command, similar to a special command interpreter, because its function implementation requires executing multiple statements, therefore, it must also have the ability to analyze and process the command line (especially the command line after do. However, when command/CMD is implemented for, it will naturally use its original command line analysis module. Therefore, for has the feature of second-level escape. For, the statements after do are analyzed and interpreted in two levels, the first level reads and interprets the for command line in command/CMD. When the second level reads and interprets the do command in for, it usually interprets the same command line multiple times.

Then, we can notice that the double % is not required when using command line parameter variables and environment variables in do, because after the first-level escape of these variables, it is replaced with a specific constant string and participates in all the execution processes of the for loop. The substitution variable must be executed (in the subcommand line after do) the process is constantly changing, and this change still needs to be achieved through escape characters. Therefore, using double % is an inevitable choice.

In addition, you need to note that the double % is not required when you use for in the command line. This is because the command interpreter has different processing methods for the command line and batch processing. In earlier dos versions, % is not considered as an escape character in the command line, so it will not be converted to or removed from the command line. Therefore, it is impossible to directly reference environment variables in the command line. When you use for, you only need one % for conversion and de-yi. In a later version of the command interpreter, the support for command line escape (mainly for environmental variables) is added, but the tradition of using single % for command line for is retained.

Variable Delay replacement in cmd is a special case, but it does not violate the above escape principles, but the environment variables in for are no longer constants.

Rmdir/S/Q % mhnet % 2> NUL 1> NUL

The general purpose of this Code is to delete the directory specified by % mhnet %./s indicates that the subdirectory is deleted, And/Q indicates that confirmation is not prompted when the directory tree is deleted, 1> NUL indicates that the information in the directory tree is deleted correctly and no output is allowed. 2> NUL indicates that the error information in the deletion process is forbidden.

Both 1 and 2 represent the input and output addresses of a data stream (NT cmd calls it a handle and msdos calls it a device ), the following table (derived from the WINXP help document "using command redirection operators (redirection operators) lists available handles.

Description of the numeric code of the handle
Stdin 0 keyboard input
Stdout 1 output to the Command Prompt window
Stderr 2 error output to Command Prompt window
Undefined 3-9 these handles are separately defined by the application and specific tools

0 keyboard input
1. output to the Command Prompt window
2 error output to Command Prompt window
3-9 these handles are separately defined by the application and specific tools.
2> NUL indicates that the program error information is not displayed.
Call attrib-r-h c:/autoexec. Bat> NUL
This sentence is actually:
Call attrib-r-h c:/autoexec. Bat 1> NUL
These 1, 2, 0 and so on are all handles. To put it bluntly, it is the code. You only need to know that 1 represents the output information, 2 represents the error information, and 0 represents the keyboard input.
If you have any questions, you can check the help and support.

 

The command line does not limit the position where the redirection symbol appears. As long as the redirection symbol is followed by the character device, the following statement is equivalent:

Echo Hello World> hello.txt
Echo Hello> hello.txt world
Echo> hello.txt Hello World
> Hello.txt echo Hello World

In the NT command lines, redirection ranges from the entire command line to a single command statement, which is restricted by the command separator &, &, | and statement block.

Echo message1> msg1.txt & Echo message2> msg2.txt
If "% target %" = "" (echo message to screen) else (echo message to File> % target %)

To sum up,> NUL means to redirect the standard output request generated by this command to an empty device. Due to the silent nature of the device, that is, it is equivalent to shielding (not hiding) the output information of this statement, while 2> NUL is blocking the standard error information output when the program executes an error after redirecting the request. They are used together to shield all output information that may be generated by this statement.

"Redirection" is a command line feature that exists from msdos, transfers the input and output requests generated by specified commands or statements to other devices through the default console, its startup flag is a "redirection symbol" (including ">>>,<". For their respective meanings, see [1.

Generally, input and output requests of the command line program are completed by defining three "ports" internally (called "handles" in NT and undefined in DOS, standard Input stdin, standard output stdout, and standard error stderr. The devices usually point to the console (console, code: con). stdin points to the console keyboard, and stdout/stderr points to the console monitor. Therefore, the console usually refers to the combination of the keyboard and monitor, a concept embodied on early mainframe terminals. Stdin can be <redirected, stdout can be>,> redirected, and stderr cannot be directly redirected in DOS, you can only use ctty or other commands to transmit control of the system to other devices.

A device is a device driver or port code that can control the hardware or port of a PC. It is usually implemented and supported by the underlying system or hardware driver. For example, the console con implemented by Io. sys, the system clock CLOCK $, the unknown device CONFIG $, the first Serial Port Aux, the first parallel port PRN, and all serial ports COM1 ~ Com4. All parallel ports LPT1 ~ Lpt3, available drive letter A:-X: And the null device NUL mentioned above. There are many other devices, such as xmsxxxx0 implemented by himem. sys, emmxxxx0 implemented by emm386.exe, and IFS $ HLP $ implemented by ifshlp. sys.

Among these devices, only con, NUL, and serial port or parallel port Devices with input/output hardware (printers, modem, etc.) can process a small amount of input/output information. They are called "character devices", and disk files are also selected as a special character device column, which greatly expands the degree of freedom and practicality of redirection, as a result, many people refer to redirection as "file redirection ".

An empty device NUL is a special device because it does not have any controllable PC hardware or port, but is just a fictitious device or port. It only exists at the software layer. Because of this, it can accept all redirected Input and Output requests without giving any response (in NT, it does not give any input information and ends the input request, in dos, 127 bytes are repeatedly filled with 0 and then the response is terminated. This feature makes it very similar to the astronomical "black hole" that can swallow all material and information ", it is also similar to the "Xuan Tao" that can be converted from Yin to Yang in philosophy ". It exists because we need a "recycle bin" that can implicitly and unconditionally absorb redundant output information or input requests, just as a "black hole" is like a huge "cosmic garbage dump ".

 

CMD has no mental disorder. It means that the Set Processing Integer is too large. Set uses double-byte storage integers and has a 32-bit storage range. That is to say, the processing range is 2 ^-31 ~ 2 ^ 31-1, your disk space exceeded this range.

I don't have a good solution to this. I only have to discard the last three digits and divide them by the 1049 approximation algorithm.

For/F "tokens = 3" % A in ('dir/-C:/^ | find "available bytes" ') do set freesize = %
Set/A freesize = % freesize :~ 0,-3%/1049> NUL
Echo freesize: % freesize %

 

> Create an object
> Append to a file
@ Prefix character. It indicates that the line is not displayed in cmd during execution. You can use echo off to disable display.
^ The leading character of the special symbol (> <&). The first character only displays the AAA second output file bbb
Echo 123456 ^> aaa
Echo 1231231> bbb
() Include commands
(Echo AA & Echo bb)
, Which is the same as the default delimiter of space.
; Annotation, indicating that it is followed by Annotation
: Label Function
│ Pipeline operations
The symbols can be used to separate different targets when the commands are the same, but the execution effect remains unchanged. If an error occurs during execution, only the error report is returned, but the program continues to execute.

First, @ is not a command, but a special identifier for DOS batch processing. It is only used to block command line echo. the following are some special tokens that may be seen in the doscommand line or batch processing:
Cr (0d) command line terminator
Escape (1B) ANSI Escape Character Guide
Space (20) Common parameter delimiters
Tab (09); = uncommon parameter delimiters
+ Copy command file Connector
*? File wildcard
"" String delimiter
| Command pipeline operator
<>>> File redirection
@ Command line echo Shield
/Parameter switch Guide
: Batch tag pilot
% Batch variable pilot

Second,: it can indeed play the role of REM annotation, and it is more concise and effective; but there are two points to note:
First, in addition to:, any character line starting with: is regarded as a label in batch processing, and all subsequent content is directly ignored, to distinguish it from a normal label, we recommend that you use a label that is not recognized by Goto, that is, a special symbol that is followed by a non-alphanumeric character.
Second, unlike REM, the following character lines are not displayed during execution, whether or not echo on is used to open the command line echo status, because the command interpreter does not regard it as a valid command line, Rem is more suitable than: In some cases. In addition, REM can be used in config. sys File.

 

You can also use the following:
If exist command
Device is a device that has been loaded in the dossystem. in Win98, there are 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 varies slightly depending on the hardware and software environment. When using these device names, you must ensure the following three points:
1. This device exists (except for devices virtualized by software)
2. the device driver has been loaded (standard devices such as aux and PRN are defined by the system default)
3. the device is ready (mainly A: B:..., com1...., lpt1)
You can run the MEM/d | find "device"/I command to review the devices loaded in your system.
In addition, in the DOS system, a device is also considered a special file, and a file can also be called a character device, because both devices and files use handle) the handle is the name, similar to the file name, but is not applied to disk management, but to memory management. The so-called device loading also refers to allocating a reference handle to it in the memory.

 

It should be enough. The reason why % is used in batch processing is determined by the features of batch processing and commands !!! I hope these will help you ...........

Http://www.cn-dos.net/forum/viewthread.php? Tid = 20558 & fpage = 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.