DOS batch command

(1)copy con[drive letter:][pathname](filename)

is used to create a .bat file or a .txt file, and then ends with Ctrl Z.


(a)copy con test.bat Enter

Ctrl Z Enter

This only creates a test.bat file

(b)copy con e:\document\test.bat Enter

echo 123456 Enter

Ctrl Z Enter

This creates a test.bat file in e:\document\, in this file The content is "echo 123456"

(2)@. The current line command is not displayed when running batch processing. It is used with echo off, that is, @ echo off, which means that the current line command of @ is not displayed, and is not displayed after The command.


(a) The batch order is:

@ echo off Enter Echo 222 Enter

display as 222

(b) If there is no @, the fart processing command is:

echo off Enter

echo 222 Enter

display as

     echo off


(3)echo, display, feedback, display commands.

(a) has echo on (default) and echo off status, indicating whether to display the command;

(b) print information, as shown in (2);

(c) text.


echo aaa > test.txt Enter

echo bbb >> test.txt Enter

, then there will be



(4 in test.txt) ):: or rem Now in front of the command line, you can comment this line

(5) pause, let the current program process pause, and display a line of information: please press any key to continue. . .


@ echo off Enter

echo 222 Enter

pause Enter

echo 333 Enter

After the display is finished 222 will prompt "Please press any key to continue. . .", when you press any key, it will display 333

(6): and goto


:beigin Enter

echo 222 Enter

goto beigin Enter

will jump back to the ":beigin" position to run.

so the print result is




until the forced end

(7)% pass the parameter

example: the content of the batch file test.bat is

           @ echo off          echo %1          echo %2          echo %0          echo %17

in the cmd window Neme "hello" "haha", will print out the following information:






(a) judgment. If %1=="hello" or if not %1=="hello"



@ echo off Enter

if %1=="hello" echo 222 Enter

in the cmd window and type neme "hello" "haha", the message will be printed as follows:


(b) to determine whether it exists. If exist test.bat del test.bat Enter

if not exist test.bat copy con test.bat Enter

ctrl +z Enter

就不不If there is test.bat, you can create a test.bat file

(c)if errorlevel number Syntax: if [not] errorlevel <number> Command to be executed

If the program return value is equal to the specified number, the condition is true, run the command, otherwise run the next sentence. (Return values ​​must be in order of largest to smallest). Many DOS programs return a numeric value after the end of the run to indicate the result (or state) of the program, called the error code errorlevel or return code. The common return code is 0, 1. The if errorlevel command can be used to determine the return value of the program, and decide to execute different commands according to different return values.