中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-11 02:10
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Introduction to Mastery of Batch Processing & Selected Compilation of Advanced Batch Processing Tutorials
Printable Version  6,124 / 43
Floor1 zhouhuang Posted 2008-07-05 16:54
初级用户 Posts 28 Credits 56
Floor2 zhouhuang Posted 2008-07-05 16:55
初级用户 Posts 28 Credits 56
### II. if…else… Conditional Statements
As mentioned earlier, DOS conditional statements mainly have the following forms: `IF ERRORLEVEL number command`, `IF string1==string2 command`, `IF EXIST filename command`.

Enhanced usage: `IF string1 compare-op string2 command`. Adding `/I` in the enhanced usage makes it case-insensitive! There are also some symbols used to judge numbers in the enhanced usage:
- EQU - Equal
- NEQ - Not equal
- LSS - Less than
- LEQ - Less than or equal to
- GTR - Greater than
- GEQ - Greater than or equal to

The above `command` can use parentheses to combine multiple commands, including the else clause. Combined commands can nest conditional or loop commands.
For example:
`IF EXIST filename ( del filename ) ELSE ( echo filename missing )`
It can also be written as: `if exist filename (del filename) else (echo filename missing)`, but this writing is not suitable for too many commands or nested commands.


### Crystal Skull Mystery
Have you ever seen such a crystal-carved human head? It is the same size as a real human skull, carved from a single piece of crystal. The teeth are neatly arranged on the jaw, the nasal bone is composed of 3 crystal stones, and each eye is a round crystal. There is also a prism at the bottom of the human head. It is estimated to be the head of a woman. There are no traces of artificial polishing on the entire crystal skull, which looks exquisite and dazzling. Even with modern technology, it would be very time-consuming and laborious to carve it. However, scientists infer that it was born as early as 36,000 years ago. Do you believe such a thing?
This crystal skull was discovered in Honduras in Central America. Could it have been made by the ancestors of the Indians? But in the 20th century, the Indians were still living a primitive life in the jungles of the Americas, wearing rags and going hungry. Who can believe that their ancestors had such superb carving skills thousands of years ago? We know that the hardness of crystal is very high, and it is very difficult to process it with ordinary tools. So what tools did the ancients use to carve it? Moreover, it is not an easy task to find such a large piece of crystal. How could they carve it so successfully with primitive hand tools? Now researchers also unanimously believe that the processors at that time did not understand the structure of crystal crystals, and they did not have modern optical and human skeletal structure knowledge. It is really amazing to be able to carve such a masterpiece with such vague knowledge! In the ancient Mayan legend, this crystal human head has some kind of magical power, and they communicate with the gods through it.
——Selected from "Unsolved Mysteries of the World"


### III. Loop Statements
1. Specified number of times loop
`FOR /L %variable IN (start,step,end) DO command `
Combined commands:
`FOR /L %variable IN (start,step,end) DO ( Command1 Command2 …… )`

2. Loop statement for a set of collections
`FOR %%variable IN (set) DO command `
`%%variable` specifies a single letter replaceable parameter. `(set)` specifies one or a group of files. Wildcards can be used. `command` is the command executed for each file, and multiple commands can be combined using parentheses.
`FOR /R path] %variable IN (set) DO command `
Check the directory tree rooted at `path`, and point to the FOR statement in each directory. If no directory is specified after /R, the current directory is used. If the set is only a single dot (.), enumerate the directory tree.
As before, `command` can be combined with parentheses:
`FOR /R path] %variable IN (set) DO ( Command1 Command2 …… commandn )`

3. Conditional loop
The above loop structure is implemented with the for command. One disadvantage of the for command loop is that the entire loop is regarded as a single command statement, involving the problem of variable delay.
Using the goto statement and conditional judgment, DOS can implement conditional loops, which is very simple. Let's look at the examples:
Example 1:
```
@echo off
set var=0
rem ************Loop starts here
:continue
set /a var+=1
echo The %var%th loop
if %var% lss 100 goto continue
rem ************Loop ends here
echo Loop execution completed
pause
```
Example 2:
```
@echo off
set var=100
rem ************Loop starts here
:continue
echo The %var%th loop
set /a var-=1
if %var% gtr 0 goto continue
rem ************Loop ends here
echo Loop execution completed
pause
```


### IV. Subroutines
In batch processing programs, external executable programs, such as exe programs, can be called, and other batch processing programs can also be called. These can also be regarded as subroutines, but it is not convenient enough. If there are many called programs, it will appear not concise enough and very cumbersome. In Windows XP, batch processing can call a program segment in this program, which is equivalent to a subroutine. These subroutines are generally placed after the main program.
Subroutine call format: `CALL :label arguments`
Subroutine syntax:
```
:label
command1 command2 ...... commandn
goto :eof
```
In the subroutine segment, the parameter `%0` refers to the label `:label`
Subroutines are generally placed at the end, and note that `exit` or a jump statement should be added at the end of the main program to avoid mistakenly entering the subroutine.
Variables in subroutines and the main program are all global variables, and their scope is the entire batch processing program.
The parameters passed to the subroutine are specified in the call statement, and are called in the form of `%1, %2 to %9` in the subroutine. The data returned by the subroutine to the main program can be directly referenced after the call ends. Of course, a return variable can also be specified. Please see the following examples.
Subroutine example 1:
```
@echo off
call :sub return 你好
echo Subroutine return value: %return%
pause

:sub
set %1=%2
goto :eof
```
Running result: 你好

Subroutine example 2: Design a subroutine to find the sum of multiple integers
```
@echo off
set sum=0
call :sub sum 10 20 35
echo Data sum result: %sum%
pause

:sub
rem The first parameter is the return variable name
set /a %1=%1+%2
shift /2
if not "%2"=="" goto sub
goto :eof
```
Running result: 65
In the win98 system, the above label call is not supported, and the subroutine must be saved as a separate batch processing program and then called.


### Gap in the Theory of Evolution
Ape-man: lived from 14 million to 8 million years ago
Australopithecus: lived from 4 million to 1.9 million years ago
Ape-man: lived from 1.7 million to 200,000 years ago
There is a gap of millions of years at the two connections of these three stages, and scientists have not found any biological fossils in between so far.
——Selected from "Unsolved Mysteries of the World"


### V. Implement Automatic Download Using ftp Command
ftp is a commonly used download tool. There are more than 40 commonly used commands in the ftp interface. I will not introduce them here. Here, I will introduce how to use the DOS command line to call the ftp command to realize automatic ftp login, upload and download, and automatic exit from the ftp program.
In fact, the ftp commands can be combined and saved as a text file, and then called with the following command.
`ftp -n -s:path]filename`
The above `filename` is the ftp command file, including the login IP address, username, password, operation commands, etc.
Example:
```
open 90.52.8.3 #Open ip
user iware #User is iware
password8848 #Password
bin #Binary transmission mode
prompt
cd tmp1 #Switch to the tmp1 directory under the iware user
pwd
lcd d:\download #Local directory
mget * #Download all files in the tmp1 directory
bye #Exit ftp
```


### VI. Implement Command Line Compression and Decompression Function Using 7-ZIP
Syntax format: (For detailed conditions, see the 7-zip help file. If you are dizzy, you can skip it and learn when you need it)
`7z <command> <base_archive_name> `
Each command of 7z.exe has different parameters `<switch>`, please refer to the help file. `<base_archive_name>` is the compressed package name. `<arguments>` is the file name, which supports wildcards or file lists.
Among them, 7z is the command line compression and decompression program 7z.exe. `<command>` is the command included in 7z.exe, listed as follows:
- a: Adds files to archive. Available parameters for the a command: -i (Include), -m (Method), -p (Set Password), -r (Recurse), -sfx (create SFX), -si (use StdIn), -so (use StdOut), -ssw (Compress shared files), -t (Type of archive), -u (Update), -v (Volumes), -w (Working Dir), -x (Exclude)
- b: Benchmark
- d: Deletes files from archive. Available parameters for the d command: -i (Include), -m (Method), -p (Set Password), -r (Recurse), -u (Update), -w (Working Dir), -x (Exclude)
- e: Extract files to the current directory or specified directory. Available parameters for the e command: -ai (Include archives), -an (Disable parsing of archive_name), -ao (Overwrite mode), -ax (Exclude archives), -i (Include), -o (Set Output Directory), -p (Set Password), -r (Recurse), -so (use StdOut), -x (Exclude), -y (Assume Yes on all queries)
- l: Lists contents of archive.
- t: Test
- u: Update
- x: eXtract with full paths Extract files to the current directory or specified directory with full paths. Available parameters for the x command: -ai (Include archives), -an (Disable parsing of archive_name), -ao (Overwrite mode), -ax (Exclude archives), -i (Include), -o (Set Output Directory), -p (Set Password), -r (Recurse), -so (use StdOut), -x (Exclude), -y (Assume Yes on all queries)


### VII. Call VBScript Program
Using Windows Script Host, you can run scripts at the command prompt. CScript.exe provides command line switches for setting script properties.
Usage: `CScript 脚本名称 `
Options:
- //B: Batch mode: Do not display script errors and prompts
- //D: Enable Active Debugging
- //E:engine: Use the engine to execute the script
- //H:CScript: Change the default script host to CScript.exe
- //H:WScript: Change the default script host to WScript.exe (default)
- //I: Interactive mode (default, opposite to //B)
- //Job:xxxx: Execute a WSF job
- //Logo: Display logo (default)
- //Nologo: Do not display logo: Do not display logo when executing
- //S: Save current command line options for this user
- //T:nn: Timeout setting in seconds: The maximum time allowed for the script to run
- //X: Execute the script in the debugger
- //U: Use Unicode to represent redirected I/O from the console

"Script name" is the script file name with extension and required path information, such as d:\admin\vbscripts\chart.vbs. "Script options and parameters" will be passed to the script. The script parameters are preceded by a slash (/). Each parameter is optional; but script options cannot be specified without specifying the script name. If no parameters are specified, CScript will display the CScript syntax and valid host parameters.


### VIII. Convert Batch Processing to Executable File
Since batch processing files are a kind of text file, anyone can edit them casually, and it is easy to destroy the commands inside. Therefore, if it is converted into a.com format executable file, not only the execution efficiency will be greatly improved, but the original function will not be damaged, and the priority can be raised to the highest. Bat2Com can complete this conversion work.
Small knowledge: In the DOS environment, the priority of executable files is from high to low: .com>.exe>.bat>.cmd, that is, if there are four types of files with the same file name in the same directory, when only the file name is typed, DOS executes name.com. If you need to execute the other three files, you must specify the full name of the file, such as name.bat.
This is a free green tool with a size of only 5.43K, which can run in pure DOS or the command line of the DOS window. Usage: `Bat2Com FileName`, which will generate an executable file named FileNme.com in the same directory, and the execution effect is the same as the original .bat file.


### Human Glow Mystery
Modern science and technology have discovered many amazing phenomena, which can make people believe many things that only exist in legends or dreams. The little angels in religious oil paintings always fly around with halos on their heads. But can you believe that there is actually a layer of colorful light invisible to the naked eye on the surface of each of our bodies! Angels only have halos on their heads, but we have glows all over our bodies. How amazing. As long as through special means, such as relying on glass coated with special paint, we can see the glow around our own bodies with our own eyes. And scientists have invented a special high-frequency electric field photography technology, which can display the condition of the human glow on a color photo, not only allowing us to feast our eyes, but also to collect it permanently. This is really an interesting thing. The scientist's experiment also found that the human glow is changing. The color of the glow in different parts of the human body is different, and when the mental and physical conditions of the human body change, the brightness, strength and size of the glow will also change accordingly.
——Selected from "Unsolved Mysteries of the World"


### IX. Time Delay
What is time delay? As the name implies, it is to delay for a period of time after executing a command before proceeding to the next command.
The application of delay is shown in the next section: "Simulate Progress Bar".
1. Use the ping command to delay
Example:
```
@echo off
echo Before delay: %time%
ping /n 3 127.0.0.1 >nul
echo After delay: %time%
pause
```
Explanation: The "/n" parameter of the ping command is used, which means how many requests to send to the specified ip. In this example, 3 requests are sent to the local ip (127.0.0.1). 127.0.0.1 can be abbreviated as 127.1. ">nul" is to shield the content displayed by the ping command.

2. Use the for command to delay
Example:
```
@echo off
echo Before delay: %time%
for /l %%i in (1,1,5000) do echo %%i>nul
echo After delay: %time%
pause
```
Explanation: The principle is very simple, that is, use a counting loop and shield the content it displays to achieve the purpose of delay.

3. Use the vbs delay function, with millisecond precision, error within 1000 milliseconds
Example:
```
@echo off
echo %time%
call :delay 5000
echo %time%
pause
exit

:delay
echo WScript.Sleep %1>delay.vbs
CScript //B delay.vbs
del delay.vbs
goto :eof
```
Running display:
10:44:06.45
10:44:11.95
Press any key to continue. . .
The above running result shows that the actual delay is 5500 milliseconds, and the extra 500 milliseconds is the time consumed for creating and deleting temporary files. The error is within one second.

4. Implement arbitrary time delay with only batch processing commands, with 10 millisecond precision, error within 50 milliseconds
Arbitrary delay operations can be implemented with only batch processing commands.
Example:
```
@echo off
set /p delay=Please enter the number of milliseconds to delay:
set TotalTime=0
set NowTime=%time%
::Read the start time, the time format is: 13:01:05.95
echo Program start time: %NowTime%
:delay_continue
set /a minute1=1%NowTime:~3,2%-100
::Read the minutes of the start time
set /a second1=1%NowTime:~-5,2%%NowTime:~-2%0-100000
::Convert the seconds of the start time to milliseconds
set NowTime=%time%
set /a minute2=1%NowTime:~3,2%-100
::Read the minutes of the current time
set /a second2=1%NowTime:~-5,2%%NowTime:~-2%0-100000
::Convert the seconds of the current time to milliseconds
set /a TotalTime+=(%minute2%-%minute1%+60)%%60*60000+%second2%-%second1%
if %TotalTime% lss %delay% goto delay_continue
echo Program end time: %time%
echo Set delay time: %delay% milliseconds
echo Actual delay time: %TotalTime% milliseconds
pause
```
Running display:
Please enter the number of milliseconds to delay:6000
Program start time: 15:32:16.37
Program end time: 15:32:22.37
Set delay time: 6000 milliseconds
Actual delay time: 6000 milliseconds
Press any key to continue. . .
Implementation principle: First set the number of milliseconds to delay, then use a loop to accumulate time until the accumulated time is greater than or equal to the delay time.
Error: The system time of Windows can only be accurate to 10 milliseconds, so there may be a 10-millisecond error in theory. After testing, when the delay time is greater than 500 milliseconds, the above delay program generally has no error. When the delay time is less than 500 milliseconds, there may be a tens of milliseconds error. Why? Because the delay program itself also has running time, and the system time can only be accurate to 10 milliseconds.
For easy reference, the above example can be changed to a subroutine call form:
```
@echo off
echo Program start time: %Time%
call :delay 10
echo Actual delay time: %totaltime% milliseconds
echo Program end time: %time%
pause
exit

::-----------The following is the delay subroutine--------------------
:delay
@echo off
if "%1"=="" goto :eof
set DelayTime=%1
set TotalTime=0
set NowTime=%time%
::Read the start time, the time format is: 13:01:05.95
:delay_continue
set /a minute1=1%NowTime:~3,2%-100
set /a second1=1%NowTime:~-5,2%%NowTime:~-2%0-100000
set NowTime=%time%
set /a minute2=1%NowTime:~3,2%-100
set /a second2=1%NowTime:~-5,2%%NowTime:~-2%0-100000
set /a TotalTime+=(%minute2%-%minute1%+60)%%60*60000+%second2%-%second1%
if %TotalTime% lss %DelayTime% goto delay_continue
goto :eof
```


### X. Simulate Progress Bar
The following is a program to simulate a progress bar. If it is applied in your own program, it can make your program more beautiful.
```
@echo off
mode con cols=113 lines=15 &color 9f
cls
echo.
echo The program is initializing. . .
echo.
echo ┌──────────────────────────────────────┐
set/p= ■<nul
for /L %%i in (1 1 38) do set /p a=■<nul&ping /n 1 127.0.0.1>nul
echo 100%%
echo └──────────────────────────────────────┘
pause
```
Explanation: The meaning of "set /p a=■<nul" is: only display the prompt information "■" and do not wrap, and no need to manually input any information. In this way, each "■" can be output one by one in the same line. "ping /n 0 127.1>nul" is the time interval for outputting each "■", that is, output one "■" every how long.


### XI. Input and Application of Special Characters
Start -> Run -> Enter cmd -> edit -> ctrl+p (meaning allowing input of special characters) -> Press ctrl+a to display a smiley face pattern.
(If you want to continue inputting special characters, press ctrl+p again, then ctrl+ a certain letter)
The above is the input method of special characters, selected from the tutorial, which is very useful. That is, use the editing program edit to input special characters, then save as a text file, and then open this file under Windows and copy the special symbols in it.
Some simple special characters can be directly input in the DOS command window and saved as a text file with redirection.
Example:
```
C:>ECHO ^G>temp.txt
```
"^G" is input with Ctrl+G or Alt+007. Entering multiple ^G can produce multiple beeps.
The application of special characters is also very interesting. Here is only one example: Backspace key
The backspace key means deleting the character to the left. This key cannot be normally input in the document, but can be entered and copied out through the edit editing program. That is, "".
Using the backspace key, a flashing text effect can be designed.
Example: Flashing text
```
@echo off
:start
set/p=Bed head bright moon light<nul
::Display text, the cursor stays at the end of the line
ping -n 0 127.0.0.1>nul
::Set delay time
set /p a=<nul
::Output some backspace characters to place the cursor at the far left of this line (the number of backspace characters can be adjusted by yourself).
set /p a= <nul
::Output space to cover the previously output text.
set /p a=<nul
::Output backspace characters again to place the cursor at the far left of this line. The number of backspace characters here must not be less than the number of spaces in front.
::Otherwise, the cursor cannot be returned to the far left.
goto start
```
Example: Output a poem of Tang poetry, each line flashes multiple times
```
@echo off
setlocal enabledelayedexpansion
set str=Bed head bright moon light 疑是地上霜 举头望明月 低头思故乡
::Define string str
for %%i in (%str%) do (
rem Since there are spaces in str, each part in str is assigned to variable %%i in turn with spaces as delimiters.
set char=%%i
echo.
echo.
for /l %%j in (0,1,5) do (
set/p=!char:~%%j,1!<nul
rem Take out each character in variable char in turn and display it.
ping -n 0 127.0.0.1>nul
rem Set the time delay for outputting each character.
)
call :hero %%i
)
pause>nul
exit

:hero
for /l %%k in (1,1,10) do (
ping /n 0 127.0.0.1>nul
set /p a=<nul
set /p a= <nul
set /p a=<nul
ping /n 0 127.0.0.1>nul
set /p a=%1<nul
)
::Text flashing
goto :eof
```


### XII. Mysterious Yoga
Yoga in India is full of mysteries. Many people have seen the strange skills of yoga practitioners with their own eyes. They can perform amazing skills such as "diagnosis from thousands of miles away", "curing diseases with external qi", "floating in the air quietly", "transmitting thoughts", etc. What is even more mysterious is that some yoga practitioners can even control the beating of their hearts, which makes the onlookers stunned. A yoga practitioner named Mahari once performed such a performance in public. When he was meditating and sitting in meditation, there was no pulse or heart sound. The doctor's electrocardiogram showed a straight line! This is really hard to believe. Another yoga practitioner named Satyarurti was even buried alive for 8 days and nights in full view of the public. During this period, he did not eat, had no pulse, no breathing, and the electrocardiogram also showed a straight line. The electrocardiogram only returned to a curve on the last day. When he was unearthed, his whole body was stiff and his reaction was numb. It took a while to gradually return to normal.
Scientists strive to explain this with scientific knowledge. They found that when the yoga practitioner is meditating and practicing, his human metabolism will decrease, the oxygen consumption will decrease, and the body can also get sufficient rest. When performing the heart stop, they either sharply increase the abdominal pressure, reduce the heart blood supply, and make its volume smaller and the activity weaker; or by violently contracting the stomach, make the corresponding nerves acutely tense, and greatly reduce the heart activity. But these can only make the yoga practitioner control the heart activity to a certain extent, and they can actually make the heart stop beating completely, which is an unsolved problem for modern science.
——Selected from "Unsolved Mysteries of the World"


### XIII. Application Skills of Random Numbers (%random%)
The system variable `%RANDOM%` returns any decimal number between 0 and 32767. Generated by Cmd.exe.
2 to the 15th power is 32768, and the above 0-32767 is actually the range of 15-bit binary numbers.
So, how to get a random number within 100? It's very simple, just take the remainder of `%RANDOM%` by 100. See the example.
Example: Generate 5 random numbers within 100
```
@echo off
setlocal enabledelayedexpansion
for /L %%i in (1 1 5) do (
set /a randomNum=!random!%%100
echo Random number: !randomNum!
)
pause
```
Running result: (each run is different)
Random number: 91
Random number: 67
Random number: 58
Random number: 26
Random number: 20
Press any key to continue. . .
The remainder operation `set /a randomNum=!random!%%100` The 100 can be any integer between 1 and 32768.
Summary: Using the system variable `%random%`, remainder operation `%%`, string processing, etc., many random processes can be realized.
Thinking question: Generate random passwords of a given length
Solution idea: Combine 26 English letters, 10 numbers, and other special characters into a string, and randomly extract several characters from it.
Reference answer 1: (simple)
```
@echo off
call :randomPassword 5 pass1 pass2
echo %pass1% %pass2%
pause
exit

:randomPassword
::---------Generate random password
::---------%1 is the password length, %2 and subsequent are return variable names
::---------The for command can only distinguish up to 31 fields at most
@echo off
set password_len=%1
if not defined password_len goto :eof
if %password_len% lss 1 goto :eof
set wordset=a b c d e f g h i j k l m n o p q r s t u v w x y z
set return=

set num=0
:randomPassword1
set /a num+=1
set /a numof=%random%%%26+1
for /f "tokens=%numof% delims= " %%i in ("%wordset%") do set return=%return%%%i
if %num% lss %password_len% goto randomPassword1
if not "%2"=="" set %2=%return%
shift /2
if not "%2"=="" goto randomPassword
goto :eof
```
Reference answer 2: (optimal)
```
@echo off
call :randomPassword 6 pass1 pass2 pass3
echo %pass1% %pass2% %pass3%
pause
exit

:randomPassword
::---------Generate random password
::---------%1 is the password length, %2 and subsequent are return variable names
::---------goto loop, variable nesting, command nesting
@echo off
if "%1"=="" goto :eof
if %1 lss 1 goto :eof
set password_len=%1
set return=
set wordset=abcdefghijklmnopqrstuvwxyz023456789_
::---------------------------Loop
:randomPassword1
set /a numof=%random%%%36
call set return=%return%%%wordset:~%numof%,1%%
set /a password_len-=1
if %password_len% gtr 0 goto randomPassword1
::---------------------------Loop
if not "%2"=="" set %2=%return%
shift /2
if not "%2"=="" goto randomPassword
goto :eof
```
Explanation: This example involves the application of variable nesting and command nesting, which will be introduced later.


### XIV. Variable Nesting and Command Nesting
Compared with other programming languages, DOS functions are relatively simple. To achieve more complex functions, various skills need to be fully used. Variable nesting and command nesting are one of such skills.
First review the key content of "string interception" earlier:
**********************************************
The unified syntax format for interception is: `%a:~]%`
**********************************************
Square brackets indicate optional. `%` is the variable identifier, `a` is the variable name, which is indispensable. The colon is used to separate the variable name and the description part. The symbol ~ can be simply understood as "offset". `m` is the offset (default is 0), and `n` is the interception length (default is all).
If the percent sign needs to be used as a single character, it must be written as `%%`
The above is the general format for DOS variable processing. If `m` and `n` in it are variables, this situation is variable nesting.
For example, set variable `word` to "abcdefghij" and variable `num` to "123456789". `%word:~4,1%` is `e`, where 4 can be taken from variable `num`, that is, `%num:~3,1%`. Written in combined form as follows:
`%word:~%num:~3,1%,1%`
It has been tested that this writing cannot be executed correctly, and writing `%word:~(%num:~3,1%),1%` is also not possible. So, how to achieve this variable nesting? This must be combined with command nesting.
What is command nesting? Simply put, first use a DOS command to generate a string, and this string is another DOS command. Use the call statement to call the string to execute it, so as to get the final result.
Example: Use the call statement to implement command nesting
```
@echo off
set str1=aaa echo ok bbb
echo 初始字符串:%str1%
echo 生成命令字符串如下:
echo %str1:~4,7%
echo 运行命令字符串生成最终结果为:
call %str1:~4,7%
pause
```
Running display:
Initial string: aaa echo ok bbb
Generated command string is as follows:
echo ok
Running command string generates the final result: ok
Press any key to continue. . .
Variable nesting and command nesting are combined and used, see the following example.
Floor3 #four# Posted 2008-07-07 09:41
中级用户 Posts 34 Credits 209
Why is there no one bumping such a good post????????????????
Floor4 laobin168 Posted 2008-07-07 15:59
新手上路 Posts 6 Credits 12
The LZ is reposting, and there are some out-of-place things mixed in!
Floor5 xuye Posted 2008-07-07 19:40
初级用户 Posts 34 Credits 79
Whether it's a repost or not, I've learned something, thanks!
Floor6 caifu Posted 2008-07-12 22:57
新手上路 Posts 5 Credits 10
Thanks for sharing
Floor7 yangzhiyi Posted 2008-07-19 19:40
中级用户 Posts 123 Credits 261
The typesetting is not very good. There are many parts without line breaks, which is hard to read clearly
Floor8 s1fmark Posted 2008-07-20 00:14
新手上路 Posts 10 Credits 18
Hard to see clearly
Floor9 taoty Posted 2008-07-21 16:45
中级用户 Posts 112 Credits 275
Why not send the e-book over?
Floor10 hder Posted 2008-07-21 19:29
新手上路 Posts 2 Credits 6
I want the electronic version
555555555555
Eyes are dizzy
Floor11 zhouhuang Posted 2008-07-21 19:51
初级用户 Posts 28 Credits 56
I don't know why I can't upload it.
Floor12 zhouhuang Posted 2008-07-21 21:08
初级用户 Posts 28 Credits 56
Share with friends who like batch processing!!
Download address: :
http://www.fs2you.com/files/0f10672e-5724-11dd-bcc2-0019d11a795f
Floor13 ufwau Posted 2008-07-22 16:23
新手上路 Posts 7 Credits 11
Dense and numerous, giving me a tingling sensation on the scalp
Floor14 magy2027 Posted 2008-07-24 00:03
新手上路 Posts 5 Credits 9
Got the sofa!!! Bump it up!!!
Floor15 magy2027 Posted 2008-07-24 00:33
新手上路 Posts 5 Credits 9
It's too messy!!!! It's not good!!!!!!!!!!!!
1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023