China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-25 12:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Repost: The妙用of DOS Batch Files View 4,162 Replies 18
Original Poster Posted 2002-10-25 00:00 ·  中国 广东 佛山 禅城区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
The Wonderful Use of DOS Batch Files

There are two types of operating systems in most computer users' machines: Windows and DOS.

The dark interface of DOS and the command-line input method cannot be compared with Windows. But now there are many applications still designed based on DOS, which can perform best under DOS, so we still need DOS.

DOS is not very easy to use, but we have to use it. The only way to solve this problem is to enhance its functions! The DOS batch file is one of them.

A batch file is like a macro. It is a text file that contains some standard DOS commands and also some special control commands for batch processing. The extension of a batch file is.bat. The DOS command processor (command.com) specifies that a batch file is an executable file. As long as you type the.bat file name in the command line, DOS will execute the statements in the.bat one by one. The function is equivalent to entering each command in the command line. Through different combinations of batch processing statements, there will be very unexpected effects. I will use some examples to illustrate to you below.

1. When we set the path, if there was an original path, it will be overwritten by the new one. If we don't want to overwrite, we must type both the new path and the old path in the command line, which is very tiring! Look at the following program:

@echo off

if "%1" == "" GOTO END

set path=%path%

path %1;%path%

:END

Explanation:

%1: The first parameter, the content is the path to be added. If there is no content, it ends.

2. Some software, when in use, either has a path pointing to it or runs in the current directory. Because such software only looks for auxiliary files such as data in the current and specified paths, so if there is no path pointing and not in the current path, the program will say "File not found". Then, can we add all paths to the environment variable PATH? Theoretically, it is possible, but DOS has a limit that the total number of characters in the command line cannot exceed 127. And PATH is to be executed by the command line, and the result is predictable. If it exceeds, DOS will unhesitatingly tell you: Environment variable overflow!

If you want to return to the original path after executing the above kind of program, look at the following program:

@echo off

set tmppath=%path%

set path=%1

%2

path=%tmppath%

set tmppath=

Explanation:

%1: The first parameter. It is the path of the software to be run, and it must be written completely.

%2: The second parameter. The file name for software operation.

3. What to do if the program exits abnormally or the Chinese system has a screen garble? It can also be solved with batch processing.

This batch processing program uses several commands provided by DOS.

@echo off

PROMPT $P$G

MODE CO80

KEYB US,437

ECHO













我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
Floor 2 Posted 2002-10-26 00:00 ·  中国 陕西 西安 电信
初级用户
★★
孤胆枪手
Credits 688
Posts 148
Joined 2002-10-26 00:00
23-year member
UID 63
Gender Male
From 陕西
Status Offline
我:╭∩╮(︶︿︶)╭∩╮。靠!!!
Floor 3 Posted 2002-10-26 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
It seems that there are basically three types of operating systems on personal computers. One type is the DOS - related ones, including various DOS and Win3.x/9x running on DOS; the second type is OS/2, WinNT - related ones, including OS/2, WinNT/2K/XP/.Net, etc.; the third type is the Unix - related ones, including various Unix, Linux, FreeBSD and so on.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 4 Posted 2002-11-28 00:00 ·  中国 广东 广州 联通
初级用户
Credits 229
Posts 37
Joined 2002-11-09 00:00
23-year member
UID 207
Gender Male
Status Offline
@echo off

set tmppath=%path%

set path=%1

%2

path=%tmppath%

set tmppath=

I've read it several times, but I still don't understand. Can you explain the meanings of these commands in detail for me?
Floor 5 Posted 2002-11-30 00:00 ·  中国 辽宁 沈阳 沈河区 联通
初级用户
Credits 140
Posts 14
Joined 2002-11-11 00:00
23-year member
UID 220
Gender Male
Status Offline
Why is your connection empty, could it be...
Floor 6 Posted 2003-04-04 00:00 ·  中国 安徽 合肥 电信
中级用户
Credits 272
Posts 43
Joined 2003-04-04 00:00
23-year member
UID 1392
Gender Male
Status Offline
It's simply a treasure!!
Floor 7 Posted 2004-05-18 00:00 ·  中国 浙江 温州 文成县 电信
初级用户
Credits 227
Posts 28
Joined 2004-05-15 00:00
22-year member
UID 24421
Gender Male
Status Offline
Bump it up first!
Floor 8 Posted 2004-05-19 00:00 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re Wengier:

  Why is MacOS not included?

Re MYS:

  1, Example one can be simplified to set path=%1;%path%; DOS 7 and above can even be used directly in the command line like this.

  2, "Some software, when used, either has a path pointing to it or is run in the current directory. Because such software only looks for auxiliary files such as data in the current and specified paths"
  The reason for specifying the path is due to the mechanism by which the DOS interpreter loads executable programs, not the path problem of the software program itself. And basically, few programs look for "data" files from the %path% path. The search path for data files was early set in the append path, and later determined by the program itself.

  3, "The total number of command line characters cannot exceed 127. And PATH is to be executed by the command line, so the result is obvious. If it exceeds, Dos will unhesitatingly tell you: Environment variable overflow"
  It is impossible to enter a command line character count exceeding the limit in the command line. Even if it is exceeded by other methods, it does not necessarily cause an environment variable overflow, which depends on the size of the environment variable reputation space. So the statement "unhesitatingly" is inappropriate.

  4, "Mode CO80 restores the screen display mode to the "black and white 80×25" mode"
  -------------------------------------
   CO40 or CO80
Specify to activate the color function of the color monitor and specify the number of characters per line. (Note the type of monitor)
  -------------------------------------

  5, "Echo











※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2004-05-20 00:00 ·  中国 辽宁 朝阳 联通
铂金会员
★★★★
痴迷DOS者
Credits 5,798
Posts 1,924
Joined 2003-06-20 00:00
23-year member
UID 5583
Gender Male
From 金獅電腦軟體工作室
Status Offline
To willsort:
I really admire you. None of the posts you made are water posts. It is suggested that you often come to the forum to have a look. Help everyone solve problems. I also hope to ask you some questions.
熟能生巧,巧能生精,一艺不精,终生无成,精亦求精,始有所成,臻于完美,永无止境!
金狮電腦軟體工作室愿竭诚为您服务!
QQ群:8393170(定期清理不发言者)
个人网站:http://www.520269.cn
电子邮件:doujiehui@vip.qq.com
微信公众号: doujiehui
Floor 10 Posted 2004-05-22 00:00 ·  中国 上海 鹏博士宽带
高级用户
★★
zhri
Credits 665
Posts 153
Joined 2004-02-23 00:00
22-year member
UID 18241
Gender Male
Status Offline
This guy is super.
^-^
Floor 11 Posted 2004-05-23 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 105
Posts 1
Joined 2004-05-22 00:00
22-year member
UID 25065
Gender Male
Status Offline
Floor 12 Posted 2004-05-23 00:00 ·  中国 广东 广州 天河区 电信
初级用户
Credits 139
Posts 9
Joined 2004-05-23 00:00
22-year member
UID 25081
Gender Male
Status Offline
Thanks, I'll figure it out!
Floor 13 Posted 2004-05-23 00:00 ·  中国 上海 闵行区 电信
初级用户
Credits 110
Posts 2
Joined 2004-05-23 00:00
22-year member
UID 25092
Gender Male
Status Offline
Haven't used DOS for a long time, but I miss that era, single-mindedness and efficiency!
Floor 14 Posted 2004-05-23 00:00 ·  中国 广东 河源 电信
初级用户
Credits 127
Posts 7
Joined 2004-03-07 00:00
22-year member
UID 19480
Gender Male
Status Offline
Are there any more in-depth uses of batch commands. As far as I know, its functions are very powerful. Some hackers abroad use it for attacks, and in the popular program battles abroad, the use of batch commands is quite frequent and practical.
Floor 15 Posted 2004-05-23 00:00 ·  中国 重庆 南岸区 电信
初级用户
Credits 257
Posts 38
Joined 2004-05-20 00:00
22-year member
UID 24855
Gender Male
Status Offline
RE ROBINXIE

I think you shouldn't ask how many batch processing commands there are, but should ask how many DOS commands you know. The special control flow commands for batch processing are just a few: if, for, call, choice, echo, pause, rem, goto, shift. Then that's it. If you don't go and learn those DOS commands related to the network, you won't understand the issue you mentioned about hackers using them for attacks.
Forum Jump: