SoFunction
Updated on 2025-04-10

Recommend a most complete and user-friendly tutorial on batch processing


8、call 

Friends who have studied assembly or C must know what the call instruction means, and the meaning here is actually the same. In a batch script, the call command is used to call another batch script from one batch script. See Example 8 (the default three script file names are, and):

: 
…… 
CALL  0 
…… 

: 
…… 
ECHO %IPA%.%1 > 
…… 
CALL   

: 
for /f "tokens=1,2,3 delims= " %%i in (%1) do call  %%i %%j %%k 

Have you seen anything wrong? Didn't see it? It’s right if you don’t see it, but there is actually nothing wrong. How can you see it! From the above two scripts, you can get the following information: 1. Script calls can be flexibly used, circularly used, and repetitively used. 2. Parameters can be used when script calls! I won’t say much about the first point. You should know the smart ones at a glance. Let’s talk about the second point here.

In this case, the parameter 0 is followed by. The effect during execution is actually to replace the parameter %1 in the case with 0. In the middle, the parameters are followed by (a file, which can also be used as parameters). The effect during execution is to use three variables in each line (it doesn't matter if you don't understand it here, you will understand it after learning the for command), corresponding to the substitution %%i, %%j and %%k. The parameter call here is very flexible and needs to be carefully experienced when using it. During the beginner's study, you can first learn to call scripts. As for the use of script parameters, you will naturally have a deeper understanding in the later learning. This is because when you can flexibly use batch scripts, how to write code more streamlined, more perfect and more efficiently naturally includes the scope of consideration. At this time, you will find that adding parameters directly when calling scripts can double the code efficiency. By the way, the scripts above are all part of the virus. In the subsequent tutorials, you will have the opportunity to see the true face of this virus. Does that mean that there are at least two batch script files in the same directory (there is only one who do you call?)? Haha, pay attention, this sentence is wrong! ! Only one can still call it--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- See Example 9 (default script file name):

net send %1 This is a call example. 
call  

The combination of these two sentences will naturally not have a good effect, because there is only one machine to send a message, who is afraid of whom? I'll give you a gift! But if there are 100 machines that execute at the same time, and each machine opens 10 and sends a message to a target machine at the same time, haha. The function of call here is to call itself, and after executing the previous net send command, then call itself, achieving the purpose of loop execution.

Give a very interesting script, and friends who are interested can experiment. Example 10 (the default script file name is):

call  

Be sure to execute it in the DOS window, otherwise you will only see a window flashing by and you will not see the final result. After execution, when the script is executed 1,260 times, don’t forget to think about why! Love is sometimes like this script. Once it falls into a dead cycle, the final result is unexpected. It’s just love, you will never wait until you are cycled for no reason so many times. Maybe the reminder of love is aborted on the third time.

9、find 

This is a search command used to search for specific strings in files, and is usually used as a preview for conditional judgments (how did I suddenly remember these four words?). The case where this command is used alone is relatively rare in batch processing because it has no practical significance. Or use example 3 to illustrate:

@echo off 
netstat -a -n >  
type  | find "7626" && echo "Congratulations! You have infected GLACIER!" 
del  
pause & exit 

First use the netstat command to check whether there is a default port 7626 in Glacier and save the result to it. Then use the type command to list the content, and then search for the string "7626" in the listed content. If you find that there is, it is prompted to be hit by the glacier, otherwise you will exit. Look, the find command is actually that simple, but one thing you must note: if you do not use the type command to list the content, but use the find command to directly find "7626" (find  "7626" && echo "Congratulations! You have infected GLACIER!"), you must give the absolute path (I tried it. There is no default path to find, which is the function of the current path, and it must be specified manually. Maybe I was wrong, welcome to correct it). Because there is a sentence in the help of the find command: If there is no specified path, find will search for text typed or generated by another command. The "another command" here naturally refers to the type command.

As for the other parameters of the find command, such as v, n, i, etc., friends who are interested, please study it yourself. This is already a DOS learning content, so I will not introduce it here. Some more subtle uses of the find command and other commands (some are simply amazing), will be introduced in the subsequent tutorials, I hope to pay attention to it.

10、for、set、shift 

Why put these three commands together? Apart from me explaining the reason, I'm afraid no one can imagine it! A very simple sentence: Actually, I don’t understand it very much! Yes, I started learning these two commands by studying viruses. Time has passed, but I still haven't fully understood them. I am afraid that I can't even understand them myself after I speak them out, and I am even more afraid that I will accidentally make a sinner if I say them wrongly. So I'll give you a script to tell you how to let these two commands leave a preliminary impression on you. In fact, it's the beginning of these two commands, not how to understand these two commands. Because it is not easy to understand such two commands (especially for)! Maybe you will praise me for being honest and not knowing if you don’t understand; maybe you will scold me and let me get out of here if I don’t understand, don’t be embarrassed or conspicuous; maybe you will say something else that is nice or bad, and you will do whatever you want. Even if I don’t agree with what you say, I will defend your right to speak to the death. See example 11:

@echo off 
for /? >  
set /? >  
shift /? > 
exit 

After execution, three files are generated under the current path, which record the help information of the for command, set command and shift command respectively. All people on earth can understand it, so I won’t say much. I have been searching for tutorials on these three commands for a long time on the Internet, but none of them are ideal, and they are basically copied help information. I think after I have fully mastered these two commands, I must write a for, set and shift tutorial summarized in my own text (about shift commands, it will also be involved when introducing batch parameters later). I will definitely do it, this is one of my wishes! One thing to note is that the introductions in the help of these three commands are relatively rigid. Although some examples are given, this is far from enough. To master these two commands, the most important thing is patience! It's not wrong, it's patience. Just reading their help text carefully requires enough patience. Do you need to further practice and understand these two commands? I will leave you the opportunity for practical practice. The key is that, depending on whether you have the patience to study it. Take a look at Example 12:

: 
CALL  
SET IPA=192.168 
CALL  0 
:NEARAGAIN 
netstat -n|find ":" > 
FOR /F "tokens=7,8,9,10,12 delims=.: " %%I IN () DO SET NUM1=%%I&& SET NUM2=%%J&& SET NUM3=%%K&& SET NUM4=%%L&& SET NUM5=%%M&& CALL  
:START 
CALL  
IF "%NUM1%"=="255" GOTO NEARAGAIN 
IF "%NUM1%"=="192" GOTO NEARAGAIN 
IF "%NUM1%"=="127" GOTO NEARAGAIN 
IF "%NUM2%"=="255" GOTO NEARAGAIN 
IF "%NUM3%"=="255" GOTO NEARAGAIN 
IF "%NUM4%"=="255" GOTO NEARAGAIN 
SET IPA=%NUM1%.%NUM2% 
ECHO START >  
PING %IPA%.%NUM3%.1> 
PING %IPA%.%NUM3%.%NUM4%>> 
FIND /C /I "from"  
IF ERRORLEVEL 1 GOTO START 
CALL  %NUM3% 
DEL  
GOTO START 


This is the virus's start script, which sets the environment variables for the virus to run. Are you looking at it so hard? I forgot the sentence written in the first paragraph of Chapter 1 (Calm down!), and you should be able to understand the patience required to learn these two commands. Just like loving someone, you have to learn to be tolerant, you can’t beat or scold her, and use your broad mind to tolerate everything about her. Even if you find that the process of loving her makes you feel like the process of reading the above code, you still have to continue to love - do love need a reason? Not needed? Need? Don't you need it... After the calm, the most intuitive gain is that your patience has become unprecedentedly sufficient. Faced with her complexity and fickleness, you will remain calm and calmly deal with scenes that you once could not cope with in your own way. Even at the end of your scar, you will sigh how great your actions were.

That's right, this is the charm of batch processing, this is the charm of love. I will thank the people who hurt you. This feeling is like being raped in the sound of your favorite music, painful and happy.

I have to repeat that various DOS commands are BODYs of batch processing (I really can't find a more suitable word to describe their relationship). Learning DOS commands is the prerequisite for learning batch processing well. Other DOS commands such as copy, dir, del, type, path, break, start, etc., as well as external commands such as ping, net, cmd, at, sort, attrib, fc, find, etc., are widely used in batch processing. The purpose of this tutorial is to teach you how to understand batch processing and how to use DOS commands to combine a perfect batch script to automatically complete what you want it to do. Flexible editing of a batch script is based on proficient in DOS commands, which is beyond the scope of this article and will not be discussed here.

Before we knew it, the third chapter was over. What came from the headset was Chen Xiaodong's "Happier than Me", which was automatically replayed every 4 minutes and 32 seconds. Although I don’t like Chen Xiaodong very much, this does not prevent me from liking music. I like this song that is so touching. Please be happier than me/I will not waste my time quitting in a mess/I will not say bitterness no matter how painful it is/I don’t need to be sorry to make up for love/At least I can fulfill your pursuit/Please remember that you are happier than me/It is worthy of my cruelty towards myself/I silently count down/In the end, I will see you clearly/Look at my good bun in your eyes/Slowly exiled. I am like an old prostitute who cannot attract guests due to his old age. I wandered in despair in the once glorious red light district, glanced at the crowd coming and going with a wooden face, silently recalling my disgraceful past, and fantasizing about the future I will face. It was not until I saw those couples who were happily snuggling together that I suddenly realized the fairness of God and the cruelty of this fairness. It can be said that I did not give a detailed introduction to the most important commands in batch scripts like echo or if. I have already said the reason, because I am also a dish and I don’t understand it very much----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- And you? Today I went to the library again and found something called "DOS Files" like gold hunting. It was hidden in a corner and was covered with dust. The five books were stacked together and they were as thick as bricks. After a brief look, I introduced a lot of things that are relatively basic and basic. Although it is already a bit time out in terms of thinking, many things have basically no value to use (this is the update speed in the information age), it is still worth watching. So I planned to come here in the afternoon, go back on holiday and study it carefully, and get familiar with those unfamiliar commands, and continue writing this tutorial. I always believe that there is no best, only better.

But unfortunately, when I went there again in the afternoon, a sign had already been erected at the entrance of the library stairs, which read out of service----The work of this semester is over. So I returned to the dormitory and planned to continue writing the fourth chapter. At this time, I got another "inspiring" news: I failed one subject in the final exam, and I was the first in the class - I failed this entire class. Depressed emotions surged into my heart in an instant, and the whole world seemed to have turned black. The canteen and convenience store have been closed one after another, and fewer people in the school are getting fewer and fewer people. Several students coming towards them are all packed with luggage, busy preparing to go home for the New Year. The loneliness and loss in their hearts are like the dark clouds before the heavy rain in summer, quickly and irresistibly occupying every corner of their hearts. Facing the cold wind of January, I was staring alone on the overpass. What else can I do? A failed man who can't even handle the final exam.

The "break between classes" seems to have been a little longer, haha, it's time for class! Starting from this chapter, we will introduce in detail several combination commands and pipeline commands commonly used in batch processing. Although these commands are not necessary, just like when you love someone, you don’t have to accompany you every day, if you lack this process, things will become complicated and imperfect. So I think pipeline commands and combination commands are batch-processed flavoring agents, which are almost indispensable.

Let’s start with the pipeline commands. Commonly used pipeline commands are as follows: |, >, >>

11、| 

I'm afraid everyone is not unfamiliar with this command. Friends who often operate DOS should know that when we view the help of a command, if the help information is relatively long and one screen cannot be displayed, DOS does not give us time to finish reading one screen and then turn to another screen, but directly displays it to the end of the help information. If you enter help to enter at the prompt, you will see all non-implicit commands supported by the current DOS version, but you can only see the last commands. The previous one has already flashed by. How to solve this problem? See example 13:

help | more 

After entering the car, you will find that the screen will automatically pause after the display is full, waiting to continue to display other information. When pressing Write Enter, it becomes one by one; when pressing the space bar, it is displayed on one screen until all of them are displayed; pressing other keys to automatically stop returning to DOS.

Why does the above phenomenon occur? The answer is very simple. Here we combine the pipeline command | and the DOS command more to achieve the goal together. Here I will briefly introduce the help command and more command, which will be of great help to understand the usage of | commands.

11.1. Help command. In fact, this command does not need to be said more, but in the above example, the use of the help command is quite special. You can directly enter the help command at the DOS prompt, and the result is that DOS can display all the non-implicit commands it supports, and in other places.