Pack you learn to batch sort collection page 1/3

Source: Internet
Author: User
Tags echo command echo display

The purpose of this tutorial is to let every friend who has read these texts remember one sentence: If love can make things easier, make it easier! The method for reading this tutorial is slow! Slowly, just like a woman and a cup of tea, you will find that many things that were just in front of you suddenly become far away, and some very distant things have suddenly returned to our eyes...

First, let's outline what batch processing is. So far, I have not been able to give a suitable definition of batch processing-Not many experts have given it-I don't know-I'm not necessarily convinced after reading it-I'm a cainiao, of course, I don't need to mention it. But I want to sum up a "more appropriate", and I believe I can explain it clearly, let more cainiao know what this is and what you can do with it. Maybe you willArticleAnd "unconditionally fall in love with batch processing", so my goal is achieved-I am trying to make you fall in love with it, so I am so jealous, what can you do ?? Really, sometimes love is so arrogant, that's no reason, it's so shameless! Really!

According to my understanding, the essence of batch processing is a collection of DOS commands in a certain order.

OK, never Claver and get to business ). Batch Processing, also known as a batch processing script, is translated into batch in English. The batch processing file suffix bat takes the first three letters. It does not have a fixed format, as long as the following line is followed, it is OK: each line can be viewed as a command, each command can contain multiple sub-commands, starting from the first line of execution, until the last line ends, it runs on DOS. Batch Processing has a distinctive feature: convenient, flexible, powerful, and highly automated. I don't want to make my own tutorials boring, becauseCode(Is the batch content a code ?) The problem is boring, and few people can calm down with full screen code. So I will use a lot of simple and practical examples to let my friends who have read this tutorial experience the charm of batch processing, feel the strange character of batch processing, and unconsciously love batch processing (dizzy, how is love? What is the relationship between batch processing and love? Answer: No !). Let's say "Gossip": to learn batch processing well, the DOS basics must be solid! Of course, flexible mind is also an important aspect.

Example 1: first, give the most easy batch processing script to familiarize everyone with its face and save the following commands as name. BAT and then execute (only the code is provided in the future, and the Save method is similar to the execution method ):

Ping sz.tencent.com> a.txt
Ping sz1.tencent.com> a.txt
Ping sz2.tencent.com> a.txt
Ping sz3.tencent.com> a.txt
Ping sz4.tencent.com> a.txt
Ping sz5.tencent.com> a.txt
Ping sz6.tencent.com> a.txt
Ping sz7.tencent.com> a.txt
Exit

Can you understand it all? Is it easy? However, after performing this batch, you can create a file named a.txt on your own. The recorded information can help you quickly find the fastest QQ server and stay away from the painful process of transferring from the server. Here> means to put the things obtained by the preceding command in the following place,> and> the growth file (think of how to destroy it ??). By the way, this batch processing can also be combined with other commands to achieve a completely automated judgment of the server speed. After the execution, the fastest Server IP address is directly displayed, isn't it great? It will be detailed later.

Example 2: an outdated example (A. BAT) is provided ):

@ Echo off
If exist c: \ progra ~ 1 \ Tencent \ Ad \ *. gif del c: \ progra ~ 1 \ Tencent \ Ad \ *. gif
A. bat

Why is this an outdated example? Very simple, because almost no one has used QQ with advertisements (Kao, My QQ also shows friends !!), So it is almost useless. However, once it was used, it could not be a small glimpse: deleting QQ ads and making the dialog box clean. The address used here is the default installation address of QQ. The default batch processing file name is A. bat. You can modify it as needed. The IF command is used in this script to determine and delete ad images in a timely manner. You only need to disable the DOS window after the command is executed, without pressing CTRL + C to forcibly terminate the command, it keeps monitoring whether there are advertisement images (qq also keeps checking whether its advertisement has been deleted ). Of course, this script occupies a little bit of memory.
Learn batch processing! It's easy to learn!

Example 3: Use the batch processing script to check whether the glacier is in progress. The script content is as follows:

@ Echo off
Netstat-a-n> a.txt
Type a.txt | find "7626" & Echo "Congratulations! You have infected glacier! "
Del a.txt
Pause & Exit

Here, the netstat command is used to check the status of all network ports. You only need to know the ports used by common trojans to easily determine whether they have been attacked by the glaciers. However, this is not certain, because the default port 7626 of the glacier can be modified completely. This section only describes the methods and ideas. Here we will introduce a slight change to the method and idea to check other Trojan scripts. Then we will change it and add the parameter and port and information list files, the script automatically detects all Trojans. Haha, isn't it fun? The combined commands & and pipeline commands are also used in the script, which will be detailed later.

Example 4: Use batch processing to automatically clear system spam. The script is as follows:

@ Echo off
If exist c: \ windows \ temp \ *. * del c: \ windows \ temp \*.*
If exist c: \ windows \ Tempor ~ 1 \ *. * del c: \ windows \ Tempor ~ 1 \*.*
If exist c: \ windows \ history \ *. * del c: \ windows \ history \*.*
If exist c: \ windows \ recent \ *. * del c: \ windows \ recent \*.*

Save the above script content to autoexec. bat, and automatically delete the system garbage every time the system is started. Pay attention to two points: 1. Dos does not support long file names, so Tempor ~ appears ~ 1. You can make changes based on your actual situation so that they meet your requirements.

How are you interested in the batch processing script? Did you find yourself falling in love with this stuff? Don't be happy too early. Love is not a simple task. It may bring you happiness and happiness. Of course, it can also make you think about jumping out of the building. If you know it's hard to continue, I 've got you! Continue to work hard. Maybe you don't necessarily get true love at the end of the day (it's possible that people who love it know it), but you can feel the whole process of love. It's sour, bitter, and spicy. Do you know if it's sweet.

Why is batch processing related to love? I am not bored, nor is it because it is interesting to write in this way. There are two reasons: first, there are many similarities between batch processing and love, in some cases, I can't explain it clearly with a "professional" line (I don't doubt my ability to express myself, but it's hard to make things clear, but what is love? How do I know !!), Maybe you will be able to get twice the result with half the effort. Why not? Second, I am in a bad status during this period. I have a cold, a fever, a headache, and a nose, but I am still suffering from emotional mental damages. I am tired of people. I am sorry to say a few words when I write a tutorial, everyone needs to buy a dog skin plaster and ignore it (maybe it's a bit effective-it won't let you look at it and then fall asleep, so you can bid your head and come to me to reimburse your medical expenses ). Maybe in the next tutorial, you will see the heroes of Yang Guo, Zhang Wuji, and other elders.

My friends who have read chapter 1 must have a preliminary impression on batch processing and know what it is. But do you know where the essence of batch processing is? In fact, it is very simple: the idea should be flexible! Nothing can be done, just unexpected. This is a little different from love, because the world of love is the world of two people, wishful thinking is not called love (Supplement: it is called Single Love. Nonsense !) Batch processing is a paradise for one person. You can do whatever you want without reaching the realm!

Batch Processing seems disorganized, but it is logically better than othersProgramThe language (such as assembly) is low. If the script you write is messy, although each line of command is correct, it may not necessarily get the desired result after the script is executed from the beginning to the end, it may be a screen's bad command or fail name. This has something in common with love: operating by steps, and missing or increasing steps may lead to unexpected results. A friend who falls in love, I believe this sentence is not certain. My love batch processing, the output result is not bad command or fail name, the screen is shown as follows: 'Your love' is not an internal or external command, it is not a running program or batch processing file. Then the cursor keeps flashing and waits for the wrong input.

Starting from this chapter, we will introduce the commonly used commands in batch processing in a simple way. Many common DOS commands are widely used in batch processing scripts, which are the body part of the batch processing script, however, batch processing is more flexible and more automated than DOS. To learn batch processing well, DOS must have a solid foundation. Here we will only describe some doscommands that are rarely used (relatively speaking). Common commands such as copy and Dir will not be introduced (these seemingly simple commands are actually very complicated, I am afraid I cannot make it clear !).

Example 5: first look at an instance. This is a very interesting script. It is a small and practical tool that shows the batch processing features in full automation. First, let's introduce the history of this script: we all know the process of installing the assembler (MASM ).Source codeAssemble, connect, and then execute the program. There are many links in the process that need to input many things, which is very troublesome (only those who have experienced it can understand ). How can this process be simplified? During our compilation course design, I was forced to write this script, which was very helpful. Check the script content:

@ echo off
:: close echo
CLS
:: clean screen
echo this programme is to make the MASM programme automate
:: display info
echo edit by CodeRed
:: display info
echo mailto me: qqkiller *** @ Sina.com
: Display info
If "% 1" = "" Goto usage
:: If input without paramater goto usage
If "% 1" = "/? "Goto usage
: If paramater is "/? "Goto usage
If" % 1 "=" help "Goto usage
: If paramater is" help "Goto usage
pause
:: pause to see usage
MASM % 1.asm
: assemble. ASM Code
If errorlevel 1 pause & edit % 1.asm
:: if error pause to see error MSG and edit the Code
link % 1.obj & % 1
:: else link. OBJ file and execute. EXE file
: usage
: Set usage
echo usage: This BAT file name [ASM file name]
echo default BAT file name is start. bat
: Display usage

Don't be scared by this pile of things first, so calm down and take a closer look (think about how the first section in Chapter 1 was written !!). The explanation of each line of commands has been given. The content after the two colons is the E text explained in the previous line. (If you are afraid of E text, you don't have to worry about it. It's easy, I understand it at a Glance. I really don't understand it. I don't know how to look up dictionaries. Is it so lazy ?), It is not displayed during script execution and does not play any role. There is a colon at the beginning of the last 5th rows. It's not a mistake! The specific functions will be detailed later. In this script, MASM and link are Assembler and connection programs. They must be related to the Edit Program and the source code you want to edit. (Of course, this script is also nonsense !) Together in the current directory. Using this batch processing script can minimize manual input. during the entire process, you only need to press a few enter keys to implement automatic conversion from the Assembly source code to the executable EXE file, intelligent judgment: if an error occurs in the source code during compilation (Assembly fails), the error message is automatically paused and automatically enters the source code editing interface after pressing any key; if the source code compilation is successful, connect and automatically execute the generated EXE file after the connection. In addition, because of the simplicity and flexibility of the batch processing command, this script also has a good option to modify, simple modification can meet the machine habits of different friends. If you are learning compilation, do not forget to take an internship!

++ ++ ++

Learn batch processing! Pack you learn (2)

Author: Unknown Article Source: network collection clicks: 2346 updated:

In this script, the following commands are displayed: @, Echo,:, pause,: And Goto, %, and if. This chapter describes these commands.

1 ,@

There are no strangers to this symbol. How can it be used for batch processing? Well, it's not its fault. batch processing is inseparable from it, or it's not perfect. It does not display the command line after it in the execution window (what a detour !). Well, in other words, the command line will not be displayed if the line has its first line. In Example 5, in the @ echo off line at the beginning, @ is used to prevent the script from displaying the echo off part at execution. Do you understand this? Still not quite familiar with it? It doesn't matter. After reading the echo command introduction, you will naturally understand it.

2. Echo

The Chinese characters are "feedback" and "Echo. It is actually a switch command, that is, it has only two States: open and close. So there are two commands, echo on and echo off. Directly executing the echo command will display the status (off or on) of the current echo command. Executing the echo off command will turn off echo display, and all subsequent commands will not display the command itself, only the execution result is displayed, unless the echo on command is executed. In Example 5, the @ command in the first line is combined with the echo off command to achieve two purposes: the echo off command itself is not displayed, and the commands in the subsequent lines are not displayed. It is a bit messy, but if you practice it, you will get a 3-minute package and will not refund the money!

Another way to use the echo command is to use it to display information! For example, in Row 5, the default BAT file name is start. bat is displayed in the window after the script is executed, but the echo command itself is not shown (Why ??).
Another method of ECHO command 2: You can directly edit a text file. Example 6:
Echo nbtstat-A 192.168.0.1> A. bat
Echo nbtstat-A 192.168.0.2> A. bat
Echo nbtstat-A 192.168.0.3> A. bat

The preceding script content can be edited by entering the content in the command line with a carriage return on each line. Finally, a file a. bat will be generated in the current directory and the result will be obtained after direct execution.

3 ,::

The function of this command is very simple. It is a comment command, which is equivalent to the REM command in the batch processing script. The content after it is not displayed during execution, and it does not play any role, because it is only a comment, but increases the readability of the script, and the/* in the C language /*............ */Similar. Everyone on Earth can understand it, so I won't say much.

4. Pause

Pause (look at your workman). I always think it is the simplest command in batch processing, simple and practical. It is used to pause the current program process and display a line of information: press any key to continue .... In Example 5, this command is used twice. The first function is to let the user see the program information, and the second is to display the wrong assembly code information (not the information it wants to display, instead, the MASM program is temporarily suspended when an error message is displayed, so that you can see where your source code is wrong ).

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.