![]() |
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-13 02:29 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS学习入门 & 精彩文章 (教学室) » Common DOS Commands (Part 2) 2 |
| Printable Version 700 / 0 |
| Floor1 欧阳慧仪 | Posted 2003-10-07 00:00 |
| 初级用户 Posts 10 Credits 140 | |
|
Built-in DOS batch commands:
@: Put this symbol in front of other commands in a batch file, and when it runs the command itself will not be displayed. For example, the @ECHO OFF command is often used at the beginning of a batch file. CALL: Call another batch file from one batch file, and after the call finishes continue executing the original batch file. Usage: CALL Note: You can also use the COMMAND /C command to accomplish the same thing. CHOICE: Selection command. This is a DOS external command, but it is mainly used in batch files. After the CHOICE command is executed it will prompt the selectable items, and at that time you choose through a keypress. Usage: CHOICE:key list] choice value, seconds] Among them, /C indicates the selectable keys, /N means do not display the prompt information, /S means case-sensitive mode, and /T in dicates that if no selection is made within the specified time, it will automatically execute one of the choice values defined in /C. The display text is the prompt information shown when the CHOICE command is executed. The result of the selection will be represented by the ERRORLEVEL value. ECHO: Display specified information. Usually shown on the screen. For example, ECHO Hello will display the text Hello on the screen. In addition, ECHO ON|OFF is used to set whether the command itself is shown when a batch file is being executed. And ECHO OFF has the same meaning as @ , but it is a standalone command and cannot be placed in front of other commands the way @ can. FOR: Run the corresponding command for the specified files. As everyone knows, under DOS many commands support wildcards, such as ? and *, letting you specify a batch of files at one time, which is very convenient. However , not all DOS commands support wildcards; for example, TYPE (the file content display command) does not. With the FOR command that is no problem, because it can make the TYPE command display multiple files at once. Usage: FOR %variable name IN (file set) DO command Note: The above is the fixed form of the FOR command; the positions of IN and DO must be correct, otherwise a syntax error will be prompted. For example, the command FOR %F IN (*.*) DO TYPE %F can make the TYPE command display multiple files at once. Note: %F is the variable name; %G etc. can also be used instead, but they must be consistent before and after. In a batch file use %%F instead. GOTO: Jump to a certain label inside the batch file and execute from there. As everyone knows, in programming it is often necessary to repeat or jump to some place and continue execution, such as the GOTO command in the BASIC language. The GOTO command in batch files can also accomplish a similar function. Usage: GOTO Here, the label name can be set freely, such as Hello. A label is set with the “:” symbol, such as “:Hello”; at that time the command GOTO Hello will jump to the location of “:Hello” and continue executing the batch file. IF: Conditional judgment command. This is a very useful batch command. Usage 1: IF EXIST filename command Meaning: if a file exist then execute a certain command. Usage 2: IF ERRORLEVEL error return code command Meaning: if the error return code is greater than or equal to the specified code then execute a certain command. Here, ERRORLEVEL means the error return code, and it is very useful. For many DOS commands, because the execution results differ (for example execution succeeds, execution fails, or is interrupted by the user, etc.), these commands will return different codes to indicate different results. The IF ERRORLEVEL command then executes different commands according to these different codes produced by different results; it is usually used after a certain command. For example, IF ERRORLEVEL 1 ECHO OK! means that if the current error return code is greater than or equal to 1, the text “OK!” will be displayed on the screen. Usage 3: IF string1==string2 command Meaning: execute a certain command when string1 and string2 are equal. PAUSE: Pause the execution of the batch file, and display the words “Press any key to continue”. REM: Add comments. Used to improve file readability; it will not be executed. You can also use :: instead. SHIFT: Change the position of replaceable parameters in a batch file. Replaceable parameters are a special kind of parameter that can only be used in batch files. These parameters are entered by the user when executing the batch command . For example, we execute the DIR /S /W command, where DIR is the command name and /S and /W are its execution parameters. In the bat ch file, these command parameters will be assigned to the replaceable parameters respectively, so /S becomes %1, /W becomes %2, and so on , while the command itself is assigned to %0. Batch files use replaceable parameters to operate on parameters entered at execution time. For example, suppose there is a batch file called MYFILE.BAT, and at the command line we execute MYFILE.BAT YES, then the value of %0 is M YFILE.BAT, and the value of %1 is “YES”. In this batch file you can use commands such as IF to judge the values of parameters like %1, and then execute different operations according to these different values, such as IF "%1"=="YES" GOTO YES. The SHIFT command takes no parameters. The execution result is that the value of %0 is changed to the original value of %1, and the original value of %1 becomes the original value of %2, and so on. Note that it is irreversible. Because there may be many runtime parameters when a batch file is executed, there may be more than 1 0, but the replaceable parameters can only go from %0 to %9. If you want to obtain parameter values after %9, you can only use the SHIFT command. At that time, the ent ire parameter list is pushed forward. The above are the built-in DOS batch commands. As you can see, there are very few of these commands. If you want to write more complex programs , it is obviously impossible to achieve that with the above commands alone. At that time, other practical batch tools are needed. The famous and practical ones include TES TIF, STRING, ASET, BATCHMAN, WBAT, etc., all of which can be downloaded from “DOS Software Category Download” under “Script Tools” . Using the above tools in batch files can achieve very powerful functions, and can even accomplish many functions of high-level language prog rams. So, if you want to write batch files, they are a good choice, not only because they have detailed docu mentation, but also because they are still under continuous development. Next we will talk about how to make batch files. Actually, making batch files is not difficult; you only need to master the method . As the number of times you do it increases, you will find it easier and easier. First use a text editor, such as the DOS built-in EDIT command or other editing tools such as PEDIT, to create a ne w blank file (of course, directly creating one with the COPY CON command is also fine), and then enter batch commands in it according to the functions you want to accomplish. If you only want to execute a collection of some DOS commands , then just enter one DOS command per line in order. But if you want to accomplish some more complex operations, then you need the above batch commands or the batch tools mentioned above. Below is a small batch program I wrote before, one that slowly increases from 1% to 100%. Everyone can use it for reference when writing their own programs. @echo off break off cls set c=0 writext 10 1 Wait... be delay 4 :loop writext 10 9 %c%%%completed. count c if not %c%==101 goto loop echo. set c= kpush /f break on In it, I used WRITEXT, COUNT, BE, and KPUSH, and these are all batch tools. WRITEXT is an enhanced tool for ECHO, and can customize display effects. COUNT is a variable calculation tool; for example, if the original value of C is 1, after executing COUNT C the value of C becomes 2. BE is a powerful batch enhancement tool included in Norton Utilties 8.0. KPUSH is a key board buffer tool. In short, by using batch commands and batch enhancement tools, we can write many powerful batch files. Everyone may as well give it a try. Many batch tools can be downloaded in “Script Tools”. Back to top -------------------------------------------------------------------------------- Undocumented DOS Commands and Parameters There are many undocumented commands and parameters in the DOS system. After collecting and organizing them, I discovered quite a lot. Because there are sev eral kinds of DOS, below I will only use MS-DOS as an example to introduce some common undocumented commands and parameters. After comparison, I found that among the various versions of MS-DOS, the 7.x versions have the most undocumented commands and parameters. These undocumented commands and pa rameters in the 7.x versions are usually not found in other DOS versions, but they are very practical. For example, the COMMAND /Z command is the only way to display the ERRORLEVEL value with DOS's own commands (of course, using other additional tools such as ERR2ENV can also do it). Undocumented DOS commands: TRUENAME: Used to display the actual path; very useful for commands such as SUBST. INSTALLHIGH: Used in CONFIG.SYS to load files into the UMB. LOGO and COMMENT: Used only in CONFIG.SYS in DOS7; usage unknown. Undocumented DOS parameters: COMMAND /F makes Fail the default option in Abort,Retry,Fail. COMMAND /D in DOS5 disables AUTOEXEC.BAT from executing automatically; in 6.0+ versions it disables the /F parameter. COMMAND /Z displays ERRORLEVEL information. COMMAND /T in DOS7.x forcibly loads COMMAND.COM permanently into conventional memory. FORMAT /AUTOTEST automatically completes the formatting process. FORMAT /BACKUP automatically completes the formatting process and prompts for a volume label. FORMAT /SELECT backs up only system-area data on the disk, equivalent to the MIRROR program. FORMAT /SELECT /U fills the boot sector and file allocation table with F6H. FORMAT /Z:n sets the cluster size on a FAT32 partition. FDISK /MBR rewrites the hard disk master boot record. FDISK /CMBR drive rewrites the master boot record on the specified drive. FDISK /PRI:size creates a primary partition. FDISK /EXT:size creates an extended partition. FDISK /LOG:size creates a logical drive on the extended partition. FDISK /PRMT|/Q prompt action / quiet mode. FDISK /PARTN saves partition table information to PARTSAV.FIL. FDISK /ACTOK for DOS7 skips the integrity test. FDISK /FPRMT for DOS7 automatically uses FAT32 and skips the prompt information. DOSKEY /APPEDIT causes DOSKEY to also apply to other programs (such as DEBUG, etc.). The usage of DOSKEY /COMMAND and/PERMANENT and/SCRSIZE and/XHISTORY is unknown. SCANDISK /CLIP for DOS7 clips long filenames into short filenames. SCANDISK /NOLOST for DOS7 does not prompt for surface testing or lost clusters. SCANDISK /NOUI and/TEXT for DOS7 use the standard DOS interface. SCANDISK /MOUNT is equivalent to Mount=Always in SCANDISK.INI. SCANDISK /TIME is equivalent to ScanTimeOut=On in SCANDISK.INI. QBASIC /QHELP enters the DOS6 full-screen help system, equivalent to executing the HELP command. QBASIC /EDCOM enters the DOS6 file editor, equivalent to executing the EDIT command. MEM /A or MEM /ALL displays HMA information. VER /R displays extended version information. DIR /Z for DOS7 means not to display long filenames. DOS=SINGLE used in CONFIG.SYS in DOS7 starts single-mode DOS. DEVICE=HIMEM.SYS /Q uses quiet mode when HIMEM.SYS is loaded. DEVICE=EMM386.EXE NOTR does not detect the Token Ring network adapter. Undocumented DOS usage: IF EXIST XMMXXXX0 ... This command can determine whether the HIMEM.SYS driver is currently installed. IF EXIST EMMXXXX0 ... This command is then used to determine whether the EMM386 driver is currently installed. DIR , used in versions before DOS7, displays all files, equivalent to DIR /A. :: This symbol can replace the REM comment command in batch files, and can speed up execution. The above are undocumented commands and parameters in MS-DOS. Some of them are very practical, and everyone may as well give them a try |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |