Batch Guide. Batch Guideby Terry Newton. This is an attempt at explaining the MSDOS batch language. It is not. complete, just the basics. For more information on individual commands. DOS's built- in HELP command. Some familiarity of DOS is assumed. CD, MD, DEL, RENAME etc. Table of Contents. All of the examples assume English DOS 6, some may run under DOS 5 but. DOS 6 adds features which are very useful to batch programmers. Here's a complete list of MS-DOS commands. The call command is used to run a script or batch program from within another script or batch program. The call command has no effect outside of a script or batch file. DOS Batch - File Examples A collection of batch files. Classic FTP: Executing a FTP script. DOS Batch - File Examples: A collection of batch files. A Quine is a program who`s only output is it`s program code. Batch Guide by Terry Newton. This is an attempt at explaining the MSDOS batch language. It is not complete, just the basics. For more information on individual commands refer DOS's built-in HELP command. With batch files, which are also called batch programs or scripts, you can simplify routine or repetitive tasks. A batch file is an unformatted text file that contains one or more commands and has a.bat or.cmd file name. A batch file or batch program is an unformatted text file that contains. In the AUTOEXEC.BAT file, use batch commands such as goto and if to have MS-DOS carry out. Batch Files: Examples (All). ListProgs.bat: 1.11: List all programs registered in Windows' Uninstall keys: NT. Set of 3 interdependent batch files for MS-DOS. Tuesday, 07 April 2009 15:29 I ran into an anomaly with the DOS environment variable %ProgramFiles(x86)% when used with an IF statement. I was trying to determine if OS was 64-bit or 32-bit from batch file. CHOICE and a version of FIND that returns an errorlevel. Batch programs are essentially sequences. DOS commands that 'type themselves' when the batch file is run. Batch files consist of control elements, internal DOS commands and external. With a little ingenuity one can duplicate most of. For the types of things. Variables. Batch uses the percentage sign (%) to mark variables. The set command. is used to assign and clear variables. When DOS reads the batch file, strings. The shift command moves everything down. The following batch illustrates the use of variables.. The. set command is used to set two variables to . Finally. the two variables are cleared to keep them from needlessly consuming environment. Speaking of environment, you should specify more space than stock DOS. CONFIG. SYS line similar to.. You can also execute command /e: 5. This can be included inside the batch itself. Redirection and Pipes. Normally, input is taken from the keyboard and output goes to the console. The < symbol causes file to be fed to the program as input. The > symbol causes the program's output to be sent to the following. The > > symbol causes the program's output to be appended to the. The following example shows how to use redirection with the FIND command.. Since we're. not interested in the actual output of the FIND command, it is redirected. Labels, Conditions and Branching. A label is any line that begins with a colon. Comments in batch code. REM. command because labels are processed before redirection symbols. The goto command is used to transfer control to another part. It can be. used to compare one string to another, determine if a file exists or determine. If the evaluation is true. The not modifier reverses. The way the command is worded it branches. Read the wording in the. Subroutines, CALL and FORMost of the elements are in place, but still no subroutines. These can. be tackled either by defining a return value and GOTO'ing the routine. GOTO's to the value of the return variable upon completion. This can be combined with the for and call. Here is an example that prints. Here is a typical made- up scenario. Suppose you have a game that requires you to change to say the C: \GAMES\MUT. MUTANT with the command line parameter /NSB. Rather. than typing all that, just put it into a batch and place it in a path directory. For example, the default path in a simple setup. When a command is typed. DOS tries the current directory. If not there it begins searching. It is convenient to place batch. If you haven't done so yet, make the directory. C: \BATCH (for example) and add it to the path line, as in.. Now, back to the mythical example, let's. MUTANT. BAT and. place it in C: \BATCH (on the path now).. Here is an example for a virus scanner that does not. The command line is stored in. SCAN this translates to . If this batch. was saved as say SCN. BAT into a path directory (got that C: \BATCH directory. SCN instead of. having to type the directory\command parameters. Launching Windows 9. Windows 9. 5 has a built- in utility for launching Windows programs and. Windows programs directly from batch, a. Previously this required special utilities to . The basic syntax is simple.. If filename is a long. The /w option causes. Other start options. For example.. start /w /max . Here is a general purpose viewer for. RUNAFILE. BAT (for example). Windows will figure out what to launched based on the selected file's. Menus for programs. The CHOICE command that comes with DOS 6 is handy for creating custom. DOS programs as well as simple Yes/No questions. Here is a simple. After the user makes a decision, the errorlevel. Raptor for example. They are listed backwards because . ANSI codes can be used to spruce up menus like these, even decent interfaces. Several menu. utility programs are also available that are called from batch. Using menuing systems.. Several freeware, shareware and commercial menuing programs are available. They're not as. fun as doing it entirely in batch but they can be more productive. A more elaborate program is something called GO- MENU from an archive. DOSVAR2. 0 from Pinnacle Software. The shareware program was something. GO- MENU. EXE is great. You can probably find it in the Sim. Tel. archives. Many others are available. Some of them can create very. I haven't..). There are two approaches. COM file like SENVAR. COM that directly. Or you can do it completely in batch. The one I've been using originated from a. I've modified it to put the temp files in C: \DOS to. ENTER. BAT'. You might need to change the. If this routine. is included in the batch program itself, set a return variable and call. How to set up SHELL and ANSITo use batch effectively you should check your CONFIG. SYS file for proper. To use color you need something like: DEVICE=C: \DOS\ANSI. SYS. or if UMBs are available (have a DOS=HIGH,UMB line) use: DEVICEHIGH=C: \DOS\ANSI. SYS. If this line is not present add it with the other DEVICE's, might help. When ANSI. SYS is active. Type in HELP ANSI. SYS at a dos prompt for a. Among the commands is the ability to re- define any key to output an. Files containing. Key Macros or ANSI Bombs, depending on the. I use key macros to redefine my function keys to. I am very used to hitting control- x instead. E X I T Return. Just be aware of the potential problem and don't. TYPE strange files. Use something like LIST. Other versions of ANSI are. If a 'set comspec=c: \command. Processing Lists of Data. A nagging problem in batch programming is how to take a list of items. One solution is to use Ed Schwartz'. COM program or a similar external utility, but there is a way to do it. The trick is to take the Dos file LOADFIX. COM and copy it to the filename. ENTER. COM then use the DATE command to read the data file and output it. LOADFIX is a seldom- used command that simply loads and runs. K of memory. It doesn't seem to have many uses. COM file. it can be very useful for data processing from batches since it can simulate. CALL'. The DATE command. Enter new date (mm- dd- yy): ' then waits for input. This has the. effect of prepending 'Enter new date (mm- dd- yy): ' in front of each line. If LOADFIX were renamed to ENTER then each line will. NEW and whatever was in the original list shows up as parameter. The obvious disadvantage of this technique is the input list. Other than that it looks like a very. The following demo batch creates a list of subdirectories. In the above example, the DIR /S switch. S were omitted there. Examples of this technique.. RESETARC. BAT and RESETALL. BAT. are a couple of batch files I made for dealing with a tape backup program. Although that's an oddball. DIZZY. BAT builds a file containing the contents. FILE. I never knew. I had so much stuff! Windows 9. 5 considerations.. The subroutine demos will work under Windows 9. If running. an old dos app that does not understand long filenames then about all that. I have no trick long- to- short name routines. I'm sure it can be done. The demo code conversions are not too bad, at least for the first six. The main difference is as many parms possible are passed in the. Terry Newton. : : overwrites ENTER. COM DIRFILE$ DIRFILE$. BAT NEW. BAT. : : windows 9. Do. Dir goto Do. Dir. ENTER. COM file (looks in 2 places, hardcode if different). DATE will exit. echo.> > dirfile$. If the list isn't very large and. The technique is to create a list. When the temp batch runs, only the. One thing. for sure, without the quotes it fails under 9. Redirection not enclosed by quotes create errors and. However. processing lists of filenames does seem to be the obvious use. Creating and running other programs from batch. Often times batch simply is not powerful enough or too slow to do the. QBasic and even debug can come in very handy. Using debug and assembly. I learn a. few commands and work with them. QBasic isn't hard to learn though, and. The all- batch solution is ok but here's. After the basic completes, the batch. Ok a couple of further explorations.. The main trick is avoiding errors from <. Fortunately just about any math. For example, if a > b then.. In the input. example it wasn't if instr(..)< > 0 but rather if not. Some more basic to batch conversions.. Once it's. satisfied with the parms it creates a temporary qbasic program that changes. After running and deleting the qbasic program. The strings must be enclosed in quotations, under Windows 9. Dos 6 the strings must. A related feature is specifying long filenames. This is a batch guide, not a qbasic guide so I won't explain the basic. I'll point out conversions needed to make. In line 1 of the qbasic code, the . Dos 6 doesn't have this . In line 5, the natural form of the comparison. This makes it very easy to make a perl- to- batch . Since the batch execution thread never. No redirection is needed, so none of those hassles, the. However it doesn't run from a path directory, for that more. If it becomes too difficult then it's. The trick is to use the FIND command to search for. The general method for Dos 6 and above is.. If you're not sure of the target OS a universal approach takes. COPY's refusal to copy empty files.. A typical example is determining if two files are identical. English, dos 6 or better).. Better to use cryptic names like.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2017
Categories |