中国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-18 09:47
47,814 topics / 349,907 posts / today 0 new / 48,259 members
DOS批处理 & 脚本技术(批处理室) » Repost: The妙用of DOS Batch Files
Printable Version  4,374 / 18
Floor1 MYS Posted 2002-10-25 00:00
元老会员 Posts 1,637 Credits 5,170 From 广东佛山
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













Floor2 hit Posted 2002-10-26 00:00
初级用户 Posts 148 Credits 688 From 陕西
Floor3 Wengier Posted 2002-10-26 00:00
系统支持 Posts 10,521 Credits 27,736
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.
Floor4 copy114 Posted 2002-11-28 00:00
初级用户 Posts 37 Credits 229
@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?
Floor5 okghost Posted 2002-11-30 00:00
初级用户 Posts 14 Credits 140
Why is your connection empty, could it be...
Floor6 superdos Posted 2003-04-04 00:00
中级用户 Posts 43 Credits 272
It's simply a treasure!!
Floor7 zgzjwz Posted 2004-05-18 00:00
初级用户 Posts 28 Credits 227
Bump it up first!
Floor8 willsort Posted 2004-05-19 00:00
元老会员 Posts 1,512 Credits 4,432
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











Floor9 Kinglion Posted 2004-05-20 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
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.
Floor10 zhri Posted 2004-05-22 00:00
高级用户 Posts 153 Credits 665
This guy is super.
^-^
Floor11 nacncyclone Posted 2004-05-23 00:00
初级用户 Posts 1 Credits 105
Floor12 ati2004 Posted 2004-05-23 00:00
初级用户 Posts 9 Credits 139
Thanks, I'll figure it out!
Floor13 wjt_lily Posted 2004-05-23 00:00
初级用户 Posts 2 Credits 110
Haven't used DOS for a long time, but I miss that era, single-mindedness and efficiency!
Floor14 robinxie Posted 2004-05-23 00:00
初级用户 Posts 7 Credits 127
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.
Floor15 SagInvoker Posted 2004-05-23 00:00
初级用户 Posts 38 Credits 257
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.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023