Batch command learning (reference textbook)

xiaoxiao2021-03-06  103

The batch file is a form of text file that contains one or more commands. Its file extension is .bat or .cmd. At the command prompt, the name of the approval file is submitted, or double-click the batch file, the system will call CMD.exe to run them one by one according to the order of each command in this file.

1. Simple batch internal order profile

Echo command

Open the echo or close the request back function, or display the message. If there is no parameters, the echo command will display the current echo setting.

grammar

Echo [{on off}] [message]

Sample: @echo off / echo hello world

In practical applications we will combine this command and redirect symbol (also known as pipe symbols, usually >>) to implement files to enter some commands to specific formats. This will be embodied in later examples.

2. @ 令

Indicates that @ @ 后,, during the invasion process (for example using batch processing

Formatting enemy's hard drives naturally can't let the other party see the command you use.

Sample: @echo off

@echo now initializing the program, please wait a minite ...

@format x: / q / u / autoset (format This command is not available / y this parameter, gratifying that Microsoft has left an Autoset parameter to us, the effects and / Y are the same.)

3. goto command

The specified jump to the label. After finding the label, the program will process the command starting from the next row.

grammar:

Goto Label (Label is a parameter, specifies the row in the batch program you want to turn.)

Sample:

IF {% 1} == {} GOTO NOPARMS

IF {% 2} == {} goto noparms (if you don't understand, you don't understand, you will have a detailed explanation.)

@Rem Check Parameters if Null show usage

: NopArms

Echo usage: Monitor.bat Serverip portnumber

Goto end

The name of the label can be random, but it is best to make a meaningful letter, let me add one: used to indicate that this letter is a label, and the goto command is based on this: to find the next step to jump there. It is best to have some explanation that you will understand your intentions.

4. REM command

Comment command, quite with / * in the C language -------- * /, which does not be executed, just a role of a comment, easy to read and modify it later.

Rem message

Sample: @Rem Here Is The Description.?

????? 5. Pause command

When you run the PAUSE command, the following message is displayed:

..

Sample:

@echo off

: Begin

Copy a: *. * D: / back

Echo please put a new disk Into Driver A

PAUSE

Goto Begin

In this example, all files on the disk A in the drive A are copied to the D: / BACK. Display Note Tips When another disk is placed in the drive A, the PAUSE command will hang the program so that you can replace the disk and press any key to continue processing.

6. Call command

Another batch program is called from a batch program and does not terminate the parent batch program. The call command accepts the label used as calling the target. If you use Call outside the script or batch file, it will not work on the command line. grammar

Call [[Drive:] [PATH] FileName [BatchParameters]] [: label [arguments]]]]]

parameter

[Drive:} [PATH] FileName

Specifies the location and name of the batch program to be called. The filename parameter must have a .bat or .cmd extension.

7. START command

Call external programs, all DOS commands and command line programs can be called by the start command.

Intrusion common parameters:

MIN starts when the window is minimized

Separate starts 16-bit Windows programs within separate spaces

High at the High Priority Category Start Application

RealTime starts an application at the RealTime priority category

Wait launches the app and waits it over

Parameters These are parameters transmitted to command / programs

When the execution application is a 32-bit GUI application, C

The Md.exe does not wait for the application to terminate the command prompt. If executed within the command script, the new behavior will not happen.

8. Choice command

Choice Use this command to allow users to enter a character to run different commands. When using, you should add / c: parameters, C: After you should write the prompt that the characters can be entered, there is no space. Its return code is 1234 ...

Such as: Choice / C: DME DEFRAG, MEM, END

Will display

DEFRAG, MEM, END [D, M, E]?

Sample:

The contents of Sample.bat are as follows:

@echo off

Choice / C: DME DEFRAG, MEM, END

IF Errorlevel 3 Goto Defrag (should judge the highest value of the value first)

IF Errorlevel 2 Goto Mem

IF Errotlevel 1 goto end

: defrag

C: / DOS / DEFRAG

Goto end

: MEM

MEM

Goto end

: END: END

Echo good bye

After this file runs, the DEFRAG, MEM, END [D, M, E]? The user can select DME, then the IF statement will make a judgment, and D represents the block segment executing the label DEFRAG, and M represents the program that is labeled MEM. Segment, e represents a block that executes the label End, and each block is finally jumped to the END Number with Goto End, and then the program will display good Bye and the file ends.

转载请注明原文地址:https://www.9cbs.com/read-123767.html

New Post(0)