Basic knowledge of batch processing

Source: Internet
Author: User
Tags echo command

Batch processing is a simplified scripting language, also known as a macro. It is used in DOS and Windows systems, which are command interpreters (usually commands) embedded in DOS or Windows systems. COM or CMD.EXE) explains the run. Similar to a shell script in Unix. The simplest example of a batch file with an extended command-line window name of. bat or. cmd is the various commands that are used to line up the command line. More complex situations require the use of command programs such as If,for,goto to run the process, as in advanced languages such as C,basic. If you need to implement more complex applications, it is necessary to take advantage of external programs, including external commands provided by the system itself and tools or software provided by third parties. A batch file, or batch program, is a plain text file consisting of a set of DOS commands that can be edited directly in Notepad or created with a DOS command, or edited with a DOS text editor Edit.exe. Under command prompt, type the name of the batch file, or double-click the batch file, and the system calls Cmd.exe to run the batch process. In general, each command occupies one line; Of course, you can use multiple commands with specific symbols (such as:&;, &&;, |, | | And so on) are separated and written to the same line, and there is the case that higher-level commands like if, for etc occupy a few lines, dozens of or even hundreds of rows of space. When the system interprets running a batch program, it first scans the entire batch program and then executes all commands down from the first line of code until the end of the program or the Exit command is encountered or an error exits unexpectedly.

echo command

Turn on echo or turn off the request Echo feature, or display a message. If there are no parameters, the Echo

Batch processing and online processing

The command displays the current echo settings.

Syntax: Echo [{on|off}] [message]

Sample: @echo Off/echo Hello World

In practical applications we will combine this command with a redirect symbol (also known as a pipe symbol, commonly used in > >> ^) to implement input commands into a particular file.

REM command

The comment command, similar to/*--------in the C language, is not executed, but only as a comment, and is only seen when editing batches, primarily for easy modification.

:: Also with REM function

But: and REM is still different when the echo is turned off, REM and: After the contents are not displayed.

Sequential batch Processing

But when the echo is turned on, REM

After the content is displayed, however:: After the content is still not displayed.

Rem [Note content]

Example: Rem hello.

Pause command

Pauses the command. When you run the Pause command, the following message is displayed:

Press any key to continue ... (or: Press any key to continue ...)

Example:

@echo off

: Begin

Copy g:*.* D:\back

echo Please insert another disc ...

Pause

Goto BEGIN

In this example, all the files on the disk in drive G are copied to D:\back. The comment that appears prompts you to add another disc

When the disk is placed in drive G, the pause command suspends the program so that you can replace the disc and press any key to continue processing.

Call command

Another batch program is called from one batch program, and the parent batch program is not terminated. Call Batch processing feature interface

The command accepts the label used as the target for the call. If you use call outside of a script or batch file, it will not work at the command line.

Grammar

Call [path file name] [tag]]

parameter [Drive:}[path] FileName

Specifies the location and name of the batch program to invoke.

Start command

Calling an external program, all DOS commands and command-line programs can be called by the start command.

For example: Startcalc.exe can open the calculator for Windows.

Common parameters:

Min Start window minimized

Separate start 16-bit Windows programs in separate spaces

High starts the application in the high priority category

REALTIME starting the application in the REALTIME priority category

Wait to start the application and wait for it to end

Parameters these parameters for transmission to the command/program

The application that executes is a 32-bit GUI application when CMD. EXE Unequal applications

Common Batch Cases

Returns a command prompt when terminated. If the command

Executed within the script, the new behavior does not occur.

Set command

Display, set, or delete variables.

Display variables: Set or set S the former shows all variables and their values that are currently defined by the batch, which displays all variables and values that begin with S.

Set and Invoke variables: for example, set AA=ABCD, which is to define a AA as ABCD. If you want to call this variable, add a percent semicolon to both sides of the AA.

For example:

Set AA=ABCD

Echo%aa%

Pause

Running this command will show "ABCD".

Delete variable: Set aa= this sentence command to delete the variable AA. If the variable AA is defined, the variable AA is removed, and if AA is not defined, then the command is meaningless.

It is necessary to note that the variables in the batch are not type-sensitive, and do not need to distinguish between int, float, char, and so on, as in the C language. For example, when the set aa=345 is executed, the value of the variable AA can be treated either as a number 345 or as a string of 345.

The SET command has extended functions, such as interactive input, string processing, numerical calculations, and so on, which belong to the Advanced command category.


This article is from "It technology _ Network Work Home" blog, please be sure to keep this source http://5201314qq.blog.51cto.com/9466704/1684024

Basic knowledge of batch processing

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.