Printer Friendly

Batch file enhancers.

Batch File Enhancers

In the last two columns we took a detailed look at, a utility gram that added more than thirty enhancements to the DOS batch file language. This time we'll round out our look at batch file enhancements by examining a pair of programs that do similar things, but with a few added twists.

POWERBATCH and BATUTIL are two very good shareware programs that will enhance your use of batch files. Both are available from shareware distributors. I purchased mine from Public Brand Software (P.O. Box 51315, Indianapolis, IN 46251; 800-426-3475) for $5 each.

The registration fee for BATUTIL is $39 and for POWERBATCH $30. With BATUTIL you will receive another program called STACKEY that allows you to place keystrokes in a buffer that can be read by another program. We'll briefly explore STACKEY a little later.

Neither POWERBATCH nor BATUTIL are for the uninitiated. Both require some familiarity with standard programming concepts. Don't let that put you off, however. If you've tried your hand at batch files and are ready for new challenges, take a look at either or both of these.


You will find BATUTIL to be somewhat more complex and sophisticated than BATCHMAN. It allows you to do more, but demands more of you. It will probably take some time to get the hang of it, but I think the investment will pay handsome rewards.

Let's begin with a look at a short, easy example. T.BAT is a batch file that simply shows the contents of another file - but with a twist.

Figure 1 shows the screen if you type T" while in the \DOCS\CIL91 directory. Now you can simply use the cursor keys or a mouse to move through the open window to choose a file to display. The code for T.BAT is shown in Figure 2.

Looks awful doesn't it? Some of the lines will be familiar to the experienced batch file writer, but the third through the fifth are peculiar to BATUTIL.

The first two lines are found in any standard batch file. The third line is new and is deciphered as follows. The first command is "batutil" and calls the BATUTIL program. The commands that follow give instructions to your computer.

When using BATUTIL, you will place BATUTIL commands between braces. Re command (AT OF) sets the screen ATtributes, including the colors remember our discussion of screen attributes from the columns about BATCHMAN?), then the {CL} command clears the screen. {CL} functions like the DOS clear screen (CLS) command, but here it clears the screen immediately after the ATtributes have been set.

The next parameter {FE %0 message) searches the batch file for the label "message." When found, it echoes every line following the label until the next line beginning with :" is found.

You also can use this command to echo lines from another file. Generally, FEcho works like this, FE <filename> <label>. You can either specify a file name or use a replaceable parameter, as we do here.

When you use "%0," BATUTIL will use the current file as the one that it searches for the label. If we had entered (FE *.bat example), the command would have looked in only files with the extension "bat" for the label "example."

The line ends with a command setting an environment variable named "foo." BATUTIL interprets this SET command in a special way.

Whenever "$F" is used in conjunction with a SET command, BATUTIL displays a list of files in the current directory. Here again we use a replaceable parameter; this time it's "%'." When a command line is read, the second word on the line is used to replace "%1." If you type "T *.BAT" the "%1" is replaced by *.BAT" and all you see is a list of the files with extension BAT.'

On the next line, we set an environment variable called "RC." RC" is a special environment variable that BATUTIL uses to store values as they are returned by various commands. The command "$F" returns a number from 0 to 4 or 9, depending on what you enter.

For example if you were to press ESC while looking at the file list, BATUTIL would set RC=2. The next line then checks the environment variable, and if it is 2, the program stops.

In the eighth line, RC is used again. If RC=0, the program returns to the label "again." "0" is returned when you choose a file from the file list displayed by the $F command. Consequently, you will be asked to choose files Until you press ESC.

The second IF" statement tests for the presence of "foo" in the environment. If it is not found, the program stops.

Finally, the next line types the contents of the file you selected. Notice that we pipe the output through MORE so that the file displays one screen at a time. If you have LIST or BROWSE on your computer, substitute "LIST $foo%" or "BROWSE %foo%" for this line.

The PAUSE command in the following line gives you time to read the final screen. You wouldn't need this line if you were using either LIST or BROWSE.

At the end is the message that appears on the left side of the screen. You can place any message here that you think would help your users to better understand their options.

This short example only demonstrates a small fraction of the capabilities of BATUTIL. Need menus? BATUTIL has many menu templates already programmed. Simply using the MEnu command you can call one of these.

The program comes with several demonstration batch files for you to study and adapt for your own use. I've been using a menu written with BATUTIL on my home PC and it looks great.

My four-year-old daughter is able to navigate the menus and use one key to load her favorite games. I think four is a bit young to learn DOS; maybe next year.)


BATUTIL is bundled with another program called STACKEY. STACKEY is a utility program that allows you to place keystrokes into a buffer to be executed at a specified time.

For example, if you want to store a file name that you will pass to WordPerfect for loading when beginning the program, STACKEY will do this for you.

STACKEY is a full-featured program (with its own 100-page manual) that harmonizes well with BATUTIL. I'll leave it to you to explore its capabilities.

Compiled Batch Files

Another way to enhance your batch files is to compile them. Many, probably most, of your batch files won't benefit from compiling. However, when you create some that are very lengthy, you will find that they execute significantly faster when compiled.

First. let's define what we mean by "compiling." Simply put, when you compile a program, whether it's a batch file or something written in BASIC, C, or Pascal, you use another program called a compiler through which you funnel the program to be compiled. As it runs, the compiler examines each line of your program and translates it into machine language. When finished, you will find a new program, usually with an EXE extension, on your disk.


POWERBATCH is a shareware batch file compiler. It has its own command set, which won't work in a standard batch file. But it does allow use of standard DOS commands within its own batch files.

To get the flavor of uncompiled POWERBATCH files, you see below the code that creates a program to move files between directories or drives. Figure 3 shows an example from the POWERBATCH source disk.

Pick file to Type <Esc> exits
91 ideas.txt
<F1> for Help>
@echo off
batutil (AT OF}{CL}{FE %0 message}{set foo=$F(%1)}
if %RC%==2 goto clear
if a%foo%==a goto clear
type %foo% ~ more
if %RC%==0 goto again
goto clear
Pick file to Type
<Esc> exits

If you have done any programming, this should be pretty easy to follow. If you're a neophyte DOS user, you may want to spend more time with your basic set of batch file commands before moving on to POWERBATCH.

Which to Use?

When thing about batch files, the question may arise about when it is appropriate to use a compiler such as POWERBATCH, when to use a batch file enhancer such as BATUTIL, and when to use plain vanilla DOS commands. The answer is a definite, "It depends."

If you want to create a program that will operate independently of any other program, you need something like POWERBATCH or DOS. If you use BATUTIL, it needs to be available to the batch file, or the program will abort.

My guess is that for users with only one computer to manage, BATUTIL and STACKEY would be most appropriate. For those who may be writing a menu that will be used in branch libraries or by many users, POWERBATCH may be worthwhile.

No matter which you choose, you will be rewarded with increased knowledge of how your computer works and greater control of its output. Not a bad payoff for a little bit of programming effort.
Variable     CLP%1,79,"a"            ;command line parm %1
Variable     CLP%2,79,"a"            ;parm %2
Variable     InChar,1                ;for keyboard responses
Compare      CLP%1,"a",,,Syntax      ;show syntax
Compare      CLP%2,"a",,,Syntax
Clear                                ;clear the screen
Upper        CLP%1                   ;make CLP%1 upper case
Upper        CLP%2                   ;make CLP%2 upper case
Write        "Move'                  ;build initial msg
Write        CLP%1
Write        to.
WriteLine    CLP%2
?FileExist   CLP%1,File1OK           ;does source file exist
Write        CLP%1                   ;write error msg
WriteLine    "not found."
GoTo         BadCopy
Label        File10K
?FileExist   CLP%2,,File2OK          ;does destination
Write        CLP%2                   ;write error msg
WriteLine    "exists!"
ReadYN       'Overwrite? [Y/N] "InChar
Compare      InChar,"N",,,BadCopy
Label        File2OK
Compare      CLP%1,CLPO/.2 ... DupFiles  ;cannot copy to itself
Copy         CLP%1 CLP%2                 ;DOS copy command
?FileExist   CLP%2,,BadCopy              ;did output file
                                          make it OK
Write        'Erasing                    ;tell user we are
WriteLine    CLP%1                       ;erasing source
Erase        CLP%1                       ;DOS erase command
WriteLine    "Move successful'           ;msg to user
Label        DupFiles
WriteLine    Cannot move a file to itself'
Label        BadCopy                       ;unsuccessful comes
WriteLine    "Move unsuccessful'            to here
Label        Syntax
WriteLine    Syntax is Move1 SourceFileName TargetFileName"
COPYRIGHT 1991 Information Today, Inc.
No portion of this article can be reproduced without the express written permission from the copyright holder.
Copyright 1991 Gale, Cengage Learning. All rights reserved.

Article Details
Printer friendly Cite/link Email Feedback
Author:Dyhuis, Randy
Publication:Computers in Libraries
Article Type:column
Date:Sep 1, 1991
Previous Article:In search of out-of-print materials.
Next Article:Automating with barcodes.

Terms of use | Privacy policy | Copyright © 2019 Farlex, Inc. | Feedback | For webmasters