What Does a Batch Maker Do?
Batch files. On DOS and Windows (any) systems, .bat files are executable files that consist of a series of commands that can contain calls to other programs. Each line of this file is a DOS command (most of the time it is like the command line we execute at the DOS prompt). You can use any text file editing tools such as Edit under DOS or notepad for Windows. Create and modify batch files.
bat
(Batch file type)
- You can control the flow of commands through conditional statements (if) and flow control statements (goto), and can also be used in batch processing
- C: AUTOEXEC.BAT under the root directory
- Simply put, the role of batch processing is to automatically execute multiple commands continuously.
- Here is the simplest application: When starting the wps software, it must be executed each time (> the previous content means the DOS prompt):
- C: \> cd wps
- C: \ WPS> spdos
- C: \ WPS> py
- C: \ WPS> wbx
- C: \ WPS> wps
- If you do this every time before using WPS, do you find it troublesome?
- Alright, use
- The expression of the parameters in the batch is% 0,% 1,% 2 ....% 9, and all parameters% * (excluding% 0)
- The initial amount of% 0 is the path of the batch itself, similar to% ~ f0
- Generally you can only take the first nine parameters, unless you use% *
- shift command allows you to get the following parameters
- Format: shift [/ n]
- n is a number from 1 to 8
- Shift will change% 0 to% 1,% 1 to% 2 ...% 9 becomes the original 10th parameter (not recommended)
- Generally use shift / 1, it will be replaced from% 1 and the original% 0 will be retained.
- Note: The parameters are also available when calling the tag, and the parameters will change back to the original when returning
- example:
- @echo off
- call: label arg1 arg2
- echo% 1
- :: will show that the echo is turned on
- echo% 2
- exit
- :label
- echo% 1
- :: arg1 is displayed
- echo% 2
- :: arg2 is displayed
- exit / b
- ECHO
- Display information, or turn command echo on or off.
- ECHO [ON | OFF]
- ECHO [message]
- To display the current echo setting, type ECHO without parameters.
- backup
- 0 Backup succeeded
- 1 No backup files found
- 2File sharing conflict prevents backup from completing
- 3User aborts backup with ctrl-c
- 4 Abort of backup operation due to fatal error
- diskcomp
- 0 sets are the same
- 1 set is different
- 2 The user aborted the comparison operation via ctrl-c
- 3 Comparison operation aborted due to fatal error
- 4 Preset error aborts comparison
- diskcopy
- 0 Disk copy operation succeeded
- 1 Non-fatal disk read / write error
- 2 The user ends the copy operation through ctrl-c
- 3 Disk copy aborted due to fatal processing error
- 4Preset error prevents copy operation
- format
- 0 Formatted successfully
- 3 user aborts formatting via ctrl-c
- 4 Formatting aborted due to fatal processing error
- 5 At the prompt "proceed with format (y / n)?", The user types n to end
- xcopy
- 0 file copied successfully
- 1 Copy file not found
- 2 The user aborted the copy operation via ctrl-c
- 4 Preset error prevents file copy operation
- 5 Disk write error during copying
- @ -Hide command
- Turning on echo off can have the effect of hiding commands, and @ can also have this effect, but you need to add one in front of each command ...
- &&, || -Judgment
- Remember to use if errorlevel to judge the success of the command? && and || can also have this effect, && means that the previous command is executed after the success of the command, and vice versa
- example:
- @echo; >>% SystemRoot% \ system32 \ test.txt && echo succeeded! || echo failed
- @pause> nul
- | -Pipeline
- Send the result of the previous command execution to the next command
- example:
- @echo Hello | find "you"
- @tasklist | find "exe"
- & -Line break
- Can write several commands on the same line
- example:
- @echo 123 & @ echo 456
- pause> nul
- ^ -Branch and escape character
- 1.Branch <br You can write a command in multiple lines
- example:
- @echo 1 ^
- 2 ^
- 3 ^
- 4
- @pause> nul
- Copy the above command, what is the execution result? This is what the line breaks do
- 2. Escape
- When we try to output an &, we will find that it cannot output ... because it is treated as a line break.
- At this time, you must ask for the escape character ^, which can deprive the special status of the first symbol behind and become an ordinary symbol (this is actually a very magical function, the reason why it is magical ... not detailed)
- example:
- @echo ^ &
- @pause> nul
- This outputs &
- In addition, when the a variable exists (set / pa = or set a = was assigned to a), you want to output% a%. First, you can use the escape character ^, you can also:
- echo %% a %%
- In this way, the two percent signs can be identified as one, which plays an escape function.
- There are some special cases that do not need to be escaped:
- echo "0000 | 000"
- It can be escaped by quotation marks, including set "a = a value", etc.
- But special cases such as the escape character when getting% 1 are difficult to handle, and there is no way to quote
- *,?-Wildcard
- What is a wildcard? For example, * .jpg means all jpg, * means all files. Now do you understand? What is the use of "?"? ? .jpg only means that there is only one jpg file with a file name, such as 1.jpg
- () -Enclosed
- Enclosed statements are a whole
- >, >>, <-redirect
- Please note here: You must add spaces before the redirection symbols ">" and ">>" just in case, because Batch is not unique, it can be used normally without spaces. But you must add spaces in daily use, otherwise the chances of failure are very high, either you cannot create / output, or the file is empty.
- Please do not use incorrect usage without adding spaces!
- echo 123 >> one.txt
- Can output 123 to append to one.txt
- echo 123> one.txt
- Can output 123 to overwrite the original content in one.txt
- nul is a reserved word in the system, so> nul will not be output to any file, which can have the effect of hiding the command execution
- 2> nul can have the effect of hiding the result of failed command execution
- <You can read data from a file into a command, but this command has to wait for user input
- example:
- @echo off
- echo 123 >> 00.txt
- set / p num = <00.txt
- echo number is% num%
- pause> nul
- Some commands require more than one> nul. To connect, you need:> nul 2> nul and so on.
- If there is a number before it, you need to add a space
- ping> nul 2> nul
- = 1> nul 2> nul ping
- = ping> nul 2> & 1 .... X> & 2 X> & 2 X> & 3 etc.
- nul refers to an empty device, which is simply to hide the output.
- 2> & 1 3> & 2 can go straight down, & 1 & 2 refers to the first, second, etc.
- Similar to the C language, batch processing also has its statement structure. The batch statement structure mainly has
- Well, let's start with a few practical ones.
- Clean up trash
- The command code is as follows:
- @echo off
- echo is removing system junk files, please wait ...
- del / f / s / q% systemdrive% \ *. tmp
- del / f / s / q% systemdrive% \ * ._ mp
- del / f / s / q% systemdrive% \ *. log
- del / f / s / q% systemdrive% \ *. gid
- del / f / s / q% systemdrive% \ *. chk
- del / f / s / q% systemdrive% \ *. old
- del / f / s / q% systemdrive% \ recycled \ *. *
- del / f / s / q% windir% \ *. bak
- del / f / s / q% windir% \ prefetch \ *. *
- rd / s / q% windir% \ temp & md% windir% \ temp
- del / f / q% userprofile% \ cookies \ *. *
- del / f / q% userprofile% \ recent \ *. *
- del / f / s / q "% userprofile% \ Local Settings \ Temporary Internet Files \ *. *"
- del / f / s / q "% userprofile% \ Local Settings \ Temp \ *. *"
- del / f / s / q "% userprofile% \ recent \ *. *"
- echo Clear system junk files is complete!
- pause
- Network settings
- @echo off
- :: Judgment
- Batch development tools
- There are many circulating on the Internet at present, I only recommend two
- iBAT (2 photos)
- 1.iBAT
- As of 2014.8.9 this tool is still being updated, the first impression-simplicity!
- 2.BatProject + DebugBatch
- These are actually two tools, but their developers are the same person. These two tools gave me the first impression-powerful! It is the best choice for debugging errors, but because it is too powerful, especially DebugBatch The method injected into the process is used for debugging.You can modify variables halfway and suspend execution, so killing software will report poison.
- Third party
- Pure batch processing is not a panacea, and the built-in third party in the system is far from satisfying our needs (if you will debug, I will not say it), so we need various third parties to make our batch processing more powerful. There is a third-party collection post in the batch processing house, which collects many third parties. If there are friends who need it, you can go there to find out. Next, I introduce a few third parties.
- DebugBatch
- Tmos.exe-command line with mouse
- Image.exe-display pictures to the command line
- CAPI-Batch calling system API, it can't be more powerful