![]() |
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-10 16:53 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Share] The Oddities in Batch Programming |
| Printable Version 31,772 / 50 |
| Floor1 willsort | Posted 2004-01-11 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
People who have studied DOS have more or less heard of batch processing. It is compact and portable, and it is a system-level source code interpretation. It runs directly without compilation and linking, which has attracted many DOS enthusiasts and programmers. The participation of many people and the emergence of countless ingenious ideas have formed the "oddities" in batch processing programming. They are not designed simply to solve some "batch processing problems", but truly treat batch processing as a language to reflect its infinite creativity. The following are some batch processing programs I have collected. They may not be technically excellent, but they are definitely breakthroughs in conception. I will continuously update and improve this topic, and I also hope that everyone will work with me to complete this "oddity" collection. Index ====== 1st floor: This topic 2nd floor: Game (Game): 1. TicTacToe (TicTacToe) 3rd floor: Mathematics (Math): 1. Random number (Random) generation, random matrix generation, total 2 2. 2K/XP expression calculation 4th floor: Clock (Clock): 1. Pause (Pause), delay (Delay), wait (Wait) or sleep (Sleep), total 5 Declaration ====== 1. To maintain the structure of this post, please try not to reply here if you are only a comrade who praises and supports; 2. Friends who have any questions and suggestions about some programs in this post, please visit the following topic http://www.cn-dos.net/forum/viewthread.php?tid=12388 3. Friends who intend to recommend programs, please pay attention to the following selection criteria: (1) The functions implemented by the program have certain universality and innovation; (2) The program does not depend on any special or customized local environment (such as the path of the program); (3) The program does not use any third-party tools or software; (4) The program is best suitable for all Windows and DOS platforms. If there are special requirements, please note; 4. This topic adopts the elimination system, that is, for codes that complete the same or similar functions, the one with the best writing quality will be adopted. When it is impossible to distinguish the advantages and disadvantages, or list them in one post at the same time, or integrate the excellent parts of the two to change them into new codes; the eliminated ones will either be listed in a separate topic or list the reference links. Update record ====== 2004.06.20: Issue the " Oddities of Batch Processing Programming" topic and link with " Oddities of Batch Processing Programming" 2005.07.16: Update the prompt variable acquisition program on floor 7 2005.08.18: Modify floor 3 to the Mathematics (Math) topic and add random number and random array generation programs 2005.08.19: Modify floor 4 to the Clock (Clock) topic and add 5 "pause" programs 2005.09.11: The Mathematics (Math) topic on floor 3 adds "Batch Processing of 2K/XP Expression Calculation" [ Last edited by willsort on 2005-9-11 at 13:35 ] |
|
| Floor2 willsort | Posted 2004-01-11 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Program: TicTacToe (Three-in-a-Row, Tic-Tac-Toe, Draughts, Pick Up Sticks)
Author: M0eRtH Original text: TicTacToe (a.k.a. Noughts''''''''n''''''''Crosses) BATch version 1.1 http://users.volja.net/sarcasmus/M0/tictactoe/tttbat.html Download: http://users.volja.net/sarcasmus/M0/tictactoe/tictactoebat.zip Environment: 1. The program should run in an English command line environment; 2. The program uses a large number of environment variables, and the size of the runtime environment space of the program should be modified; 3. To run the program on WIN2K/XP, support for CHOICE is required; Remarks: This is the first real game-like program I have seen written in batch processing. Although the program does not provide an AI opponent, its beautiful structure is still worthy of praise. The garbled characters in the main text are because the author used ANSI table characters. Similar: Sherlock Holmes Q&A: http://dos.e-stone.cn/dosbbs/dispbbs.asp?boardID=6&ID=8272 Maze in ZD Manor: http://zdland.xiloo.com/planets/psa.html Main text: @echo off |
|
| Floor3 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
### Mathematics - Random
1) Random Number Generator: After running, it can generate a random integer from 00 to 99 and save it in the environment variable %_random%. If you want to generate more complex random numbers, you can also modify this program. For example, combining two generated random numbers can get a random number from 0000 to 9999; adding a decimal point in front of the random number can get a random decimal from 0.00 to 0.99; removing the first underscore in prompt _$T$_:: can get a random number from 0 to 9; and using debug can remove the prefix 0 of some random numbers. According to the above methods, you can combine to get random numbers in any form. 2) Random Array Generator: After running, it will generate a random probability distribution matrix diagram. This diagram has 24 rows and 63 columns, composed of the characters "-" (false) and "o" (true). Every three rows from top to bottom form a group, and the distribution probability of o shows a decreasing trend. Among them, the left graph in the matrix is the distribution of true and false sequences, and the right graph is the comparison of the number of true and false. ### Mathematics - Expressions 1) 2K/XP Expression Calculation Batch Processing, originally created and maintained by Brglng. When reposting, the document part in the program is simplified. You can check the complete code and document through the following link. {16534} 2K/XP Expression Calculation Batch Processing http://www.cn-dos.net/forum/viewthread.php?tid=16534 [ Last edited by willsort on 2005-9-11 at 13:37 ] |
|
| Floor4 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
1、Pause, Delay, Wait, Sleep
1) for+set+if, with a time precision of 0.01 seconds, applicable platforms: WinNT/2K/XP/2003. Use for to parse the variable %time% and store it as two time points %start% and %now%, then use set /a to calculate the time difference between the two time points, and finally use if to judge whether the time difference has reached the set pause time. 2) The sleep function in VBS scripts, with a time precision of 0.001 seconds, applicable platforms: Win9x/WinNT series. Dynamically create a VBS script that calls the sleep() function, and then use the command-line version of the Windows Script Host, cscript, to call it. 3) The message sending interval of ping, with a time precision of 1 second, applicable platforms: Win9x/WinNT series. Your Windows system needs to have the TCP/IP protocol of the network card normally installed. There are two schemes. Scheme two is not recommended. See the theme The Oddities of Batch Programming on floors 12 and 13: (1) Use the interval time between two ping message sends. When ping sends multiple messages, after getting the response of the previous message, it will wait for 1 second before sending the next message. And this response time varies due to the model, system, and network configuration. Among them, the local loopback address 127.0.0.1 is relatively constant because it responds immediately. Other addresses mostly have significant differences. This method needs to wait a longer time. It is to specify the number of messages sent as one more than the waiting time, because the first message is not waited for. The IP address must be 127.0.0.1. The program to wait for 2 seconds is as follows: (2) Use the maximum waiting time of ping. ping sends an "Internet Control Message Protocol (ICMP)" echo request message to 0.0.0.1. Because 0.0.0.1 is an IP address that cannot respond to ping requests, by default, ping will wait for a certain maximum response time - it stops waiting after 4 seconds, and -w can change this maximum response time for each message send. And if the IP address is changed to 127.0.0.1 or other IP addresses with very short response times that respond immediately, then -w loses its effect because the waiting time for each send will not reach the maximum response time, and the delay will be shortened. This method needs to wait a longer time. You can directly use -w to specify, but you need to subtract a certain sending delay. This delay needs to be measured in advance, otherwise there will be an error of less than 1 second; and the IP address must be an address that does not respond to requests. The program to wait for 2 seconds is as follows: 4) The default selection waiting function of choice, with a time precision of 1 second, applicable platforms: MS-DOS/Win9x/WinNT series. /t:y,2 sets the default selection character to y, the waiting time is 2 seconds, /n prohibits the prompt from appearing on the command line, and the role of "rem|" is to prohibit choice from accepting key presses from the keyboard, so that the pause will not be accidentally terminated by pressing y or other keys. 5) ASCII assembly code, with a delay precision of 0.001 seconds, applicable platforms: MS-DOS/Win9x/WinNT. German Herbert Kleebauer gave a general solution. By indirectly generating a sleep.exe program through an ASCII assembler to achieve delay. This program is divided into DOS and Win modules, which respectively call DOS system interrupt services and Windows APIs. |
|
| Floor5 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Below is a program for drawing in character mode. The original text came from the DOS board of NetEase Guangzhou.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=15763&i=15763&al=5&n=0&l=40&back=2&st=0&kw=MAP This program works in a very crude way, but it already has some basic functions, such as drawing, erasing, changing the brush character, saving and extracting character drawings, backing up and restoring character drawings, making character drawings executable, and so on. The program uses the support functions of ANSI.SYS, so the box character after ECHO is actually the symbol with ASCII code 27. Under DOS, you can enter this character in EDIT by pressing CTRL+P and then ESC. ------------------------------------
|
|
| Floor6 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
The following is a program to draw a character dog on the command line prompt. The original text is from the DOS version of NetEase Beijing Station.
http://fe4.bj.163.com/cgi/readsrh?b=DOS&t=38819&i=38819&al=5&n=0&l=40&back=2&st=0&kw=DOS%B5%C4%CD%BC%D0%CE The program requires ANSI support. There are defects in it, and the solution can be found by querying the original website. --------------------------------------
|
|
| Floor7 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Here is the translation:
Here is a program to obtain PROMPT system status data. The original text is from the DOS version of NetEase Guangzhou Station. http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=25501&i=25609&al=5&n=0&l=40&back=2&st=1&kw=willsort When running, add the variable name where the data is stored and the PROMPT - corresponding variable name, for example: getvar curver $v The extractable system status data includes: $T Current time $D Current date $P Current drive and path $V System version number $N Current drive ------------------------------------ ------------------------------------ Update on 2005.07.16: [ Last edited by willsort on 2005-10-29 at 12:36 ] |
|
| Floor8 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Here is the translation:
The following is a timer program. The original text comes from the DOS version of NetEase Guangzhou Station. http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=13486&i=15375&al=5&n=40&l=40&back=2&st=1&kw=willsort The CURRENT.BAT in the program can be replaced with the content you need to execute. The time of the FIND sentence can be set according to your needs, and can also be replaced with the parameter %1. It can also be changed to TIME to DATE to complete the function of regular execution. ------------------------------
|
|
| Floor9 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
1、Sharing
1)Delete the default shares of the win2k/xp system Original text from "Batch Processing Concise Tutorial" http://www.realhack.org/article/articleshow.asp?ArticleID=954 2)Program to PING all IPs in a certain segment Original text from the DOS version of NetEase Beijing Station. http://fe4.bj.163.com/cgi/readsrh?b=DOS&t=94897&i=96159&al=5&n=0&l=40&back=2&st=1&kw=willsort Enter a.bat 0 1 2 3 4 5 6 7 8 9 at the command line, and it will display all IP addresses in a certain segment 192.168.1.0 - 192.168.1.99. Just change echo to ping. The choice and if statements are for waiting for the user to judge whether to continue and can be deleted, but it will be more troublesome to interrupt the program. [ Last edited by willsort on 2005-8-19 at 17:17 ] |
|
| Floor10 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Here is the translation:
The following is a program to modify the update date of a file. The original text comes from the DOS version of NetEase Beijing Station. http://fe4.bj.163.com/cgi/readsrh?b=DOS&t=85861&i=85878&al=5&n=0&l=40&back=2&st=1&kw=willsort There are several errors in the original code. The following is the corrected version. --------------------------------------
|
|
| Floor11 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
The following is a file traversal program, originally from the DOS version of NetEase Guangzhou Station.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=21718&i=21882&al=5&n=0&l=40&back=2&st=1&kw=willsort The original text uses two external programs, VARSET and LMOD, may be downloaded from this station or the new DOS era @echo off rem ///////////////////Search all *.txt files in all directories/////////////////// rem Find *.txt in the current directory (root directory) for %%a in (*.txt) do type %%a rem The following is to find all *.txt in all subdirectories of the current directory (root directory) set i=1 set j=1 set filenum=0 set dirnum=0 varset root=FULL of . >temp.bat call temp.bat varset rootdir=string(3) %root% >temp.bat call temp.bat dir /ad /b /s >temp.txt varset dirnum=lines temp.txt >temp.bat call temp.bat :loop1 type %root%\temp.txt | %root%\LMOD /L%i% set curdir= >%root%\temp.bat call %root%\temp.bat varset curdir=string(3) %curdir% >%root%\temp.bat call %root%\temp.bat cd %curdir% echo %curdir% set j=1 :loop2 %root%\varset filenum=files *.txt >%root%\temp.bat call %root%\temp.bat if %filenum%==0 goto end2 dir *.txt /b | %root%\LMOD /L%j% set curfile= >%root%\temp.bat call %root%\temp.bat type %curfile% if %j%==%filenum% goto end2 %root%\varset j=%j%+1 >%root%\temp.bat call %root%\temp.bat goto loop2 :end2 cd %rootdir% if %i%==%dirnum% goto end1 %root%\varset i=%i%+1 >%root%\temp.bat call %root%\temp.bat goto loop1 :end1 del %root%\temp.bat del %root%\temp.txt set i= set j= set filenum= set dirnum= set root= set rootdir= set curdir= set curfile= That's not a correct translation. Let's do it properly: The following is a file traversal program, originally from the DOS version of NetEase Guangzhou Station. http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=21718&i=21882&al=5&n=0&l=40&back=2&st=1&kw=willsort The original text uses two external programs, VARSET and LMOD, which may be downloaded from this station or the new DOS era. @echo off rem ///////////////////Search all *.txt files in all directories/////////////////// rem Find *.txt in the current directory (root directory) for %%a in (*.txt) do type %%a rem The following is to find all *.txt in all subdirectories of the current directory (root directory) set i=1 set j=1 set filenum=0 set dirnum=0 varset root=FULL of . >temp.bat call temp.bat varset rootdir=string(3) %root% >temp.bat call temp.bat dir /ad /b /s >temp.txt varset dirnum=lines temp.txt >temp.bat call temp.bat :loop1 type %root%\temp.txt | %root%\LMOD /L%i% set curdir= >%root%\temp.bat call %root%\temp.bat varset curdir=string(3) %curdir% >%root%\temp.bat call %root%\temp.bat cd %curdir% echo %curdir% set j=1 :loop2 %root%\varset filenum=files *.txt >%root%\temp.bat call %root%\temp.bat if %filenum%==0 goto end2 dir *.txt /b | %root%\LMOD /L%j% set curfile= >%root%\temp.bat call %root%\temp.bat type %curfile% if %j%==%filenum% goto end2 %root%\varset j=%j%+1 >%root%\temp.bat call %root%\temp.bat goto loop2 :end2 cd %rootdir% if %i%==%dirnum% goto end1 %root%\varset i=%i%+1 >%root%\temp.bat call %root%\temp.bat goto loop1 :end1 del %root%\temp.bat del %root%\temp.txt set i= set j= set filenum= set dirnum= set root= set rootdir= set curdir= set curfile= |
|
| Floor12 willsort | Posted 2004-01-12 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Here is the translation:
The following is a program that receives keyboard input strings. The original text comes from the teaching room of this site. http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=12&replyID=34149&ID=5283&skin=1 The key technique in this article lies in the skillful combination of FC and DEBUG. The usage of %TEMP%.\filename.ext is also very skillful. The usage of %%? is also novel. ---------------------------------------
|
|
| Floor13 pizigao | Posted 2004-01-13 00:00 |
| 银牌会员 Posts 292 Credits 1,063 | |
| Floor14 pizigao | Posted 2004-01-13 00:00 |
| 银牌会员 Posts 292 Credits 1,063 | |
|
Brother willsort, please take a look at my post
http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=9&ID=8920 |
|
| Floor15 zww3008 | Posted 2004-01-14 00:00 |
| 初级用户 Posts 21 Credits 197 | |
|
These are all very classic batch processing programs, which are very worthy for beginners to learn, refer to and experience. If you don't want the post to be filled with water, then please ask the moderator to put it at the top! Don't let the post sink.
|
|
| 1 2 3 4 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |