home *** CD-ROM | disk | FTP | other *** search
- Batch Logs
- (PC Magazine Vol 5 No 1 January 14, 1985 User-to-User)
-
- In developing a large software project you're likely to end up
- writing a complex batch file to handle all the compiles, assemblies
- and links required. Sitting around for hours monitoring the batch
- file to make sure everything works properly isn't fun. It would be
- handy if all the output from a batch file could be redirected to a
- file to be inspected later. Unfortunately, you can't do it simply
- by redirecting the output of the master batch file: build.bat>logfile.
- However, there is an obscure way to do the same thing. First,
- make the very last line of your batch file the DOS command EXIT. But
- before running this batch file, load another copy of COMMAND.COM and
- redirect its output to the log file: command>logfile.
- With this trick, all screen output is redirected to your log file.
- However, since the DOS prompt disappears and your typing will no longer
- echo on the screen, be sure to type the name of your batch file
- carefully, since you can't see it. All the output of the batch file
- will now to into your log file and the EXIT command at the bottom of
- the batch file will return everything to normal.
- Editor's Note: This technique demonstrates yet another benefit of
- loading COMMAND.COM as a secondary command processor. An even more
- interesting one is during a session with a windowing program that
- doesn't normally give you access to DOS commands. It's fairly simple
- to record a batch session without loading in a second COMMAND.COM;
- just toggle your printer echo on with Ctrl-PrtSc or Ctrl-P and
- everything that appears on the screen will also be printed. When
- you're done, toggle it off the same way.
-
- -----------------------------------------------------------------
- Better Pauser
- (PC Magazine Vol 5 No 1 January 14, 1986 User-to-User)
-
- The DOS PAUSE command in a batch file will have the computer stop
- and wait for a key. STOP.COM replaces the PAUSE command and gets rid
- of the "Strike a key when ready . . ." message. You can instruct
- STOP.COM to proceed when any key is pressed, or wait for a specific
- key (extended codes are allowed). Create STOP.COM with STOP.BAS
- below. STOP.COM will be either 11 or 19 bytes long depending on your
- choice of trigger keys.
-
- 100 'STOP.BAS
- 110 DIM D(19):FOR Y=1 TO 11:READ D(Y):NEXT:DEF SEG=&H40
- 120 PRINT "Type specific key OR '?' for any key ";
- 130 LY$=INKEY$:IF LY$="" GOTO 130
- 140 TL=PEEK(26):TL=TL-2:IF TL<30 THEN TL=60
- 150 C1=PEEK(TL):C2=PEEK(TL+1)
- 160 IF C1<>0 THEN 190
- 170 SI=19:FOR Y=10 TO 19:READ D(Y):NEXT
- 180 D(15)=C2:D(6)=60:D(7)=0:GOTO 200
- 190 SI=11:IF C1<>63 THEN D(6)=60:D(7)=C1
- 200 OPEN "STOP.COM" AS #1 LEN=1
- 210 FIELD 1,1 AS PH$
- 220 FOR Y=1 TO SI:LSET PH$=CHR$(D(Y)):PUT #1:NEXT
- 230 PRINT:PRINT "STOP.COM created.":CLOSE #1:END
- 240 DATA 184,8,12,205,33,56,192,117,247,205
- 250 DATA 32,180,8,205,33,60,0,117,239,205,32
-
- The following is an assembler code version that will proceed only
- when the F1 key is pressed.
-
- xxxx:0100 B8080C MOV AX,0C08
- xxxx:0103 CD21 INT 21
- xxxx:0105 3C00 CMP AL,00
- xxxx:0107 75F7 JNZ 0100
- xxxx:0109 B408 MOV AH,08
- xxxx:010B CD21 INT 21
- xxxx:010D 3C3B CMP AL,3B
- xxxx:010F 75EF JNZ 0100
- xxxx:0111 CD20 INT 20
-
- Use DOS 2.0 or later DEBUG by first typing in DEBUG STOP.COM,
- then typing A, then the rightmost two columns above. Finish it off
- by hitting the Enter key twic, then typing RCX, then 13, then W, then
- Q, hitting the Enter key after each. The 3B in the CMP AL,3B line is
- the extended scan code for F1; to use F2 as the trigger, replace the
- 3B with 3C, etc.
- Editor's Note: By creating STOP.COM and inserting the word STOP
- in a batch file, you do halt the operation of the batch file without
- the conventional PAUSE message. However, you have to tell the user to
- hit a key, presumably with an ECHO subcommand, so you're really not
- gaining much, and you have to precede the STOP line with an ECHO OFF,
- or you'll see the word STOP on-screen. In addition, the PAUSE works
- so well that if the "Strike . . ." message is really a bother, just
- change it. Use DEBUG with a copy of COMMAND.COM. At the DEBUG
- prompt, type RCX and hit the Enter key twice to see how long your
- version of COMMAND.COM is. Then enter the following DEBUG search
- instruction: S 100 XXXX "Strike a key" (replacing the XXXX with the
- length reported when you typed RCX). The last four digits of the new
- number DEBUG reports are the address of the "Strike . . ." message --
- for DOS 3.1 the address would be 491E. You can use the DEBUG E command
- to replace it with something the same length, such as "Hit any key to
- continue" or you can blank it out if you want by entering 23 spaces
- between a pair of quotation marks. If the new message is shorter than
- the old, pad out the difference with spaces.
-
-
- -----------------------------------------------------------------
-
- Interactive Batch Files
- (PC World January 1986 Star-Dot-Star)
-
- DOS batch file commands don't support one very useful feature --
- user interaction. The program QUERY.COM, when executed, displays a
- message and waits for a single-keystroke reply. A batch file can then
- test ERRORLEVEL to determine the user's selection.
- To use the program, type QUERY followed by the text you want
- displayed as a prompt, then an "at" sign (@) followed by the valid
- response characters. QUERY will set the ERRORLEVEL value to correspond
- to the sequence of the characters listed.
- For example, when the lines shown in USERTEST.BAT execute, the PC
- will display the message "Do you want to see a list of files?" and wait
- for you to press Y or N (upper- or lowercase); all other keystrokes are
- ignored. If you press Y, ERRORLEVEL will be set to 1. If you type N,
- ERRORLEVEL will be set to 2. Note that because DOS performs an "equal
- to or greater than" test for ERRORLEVEL, you must test the highest
- values first.
- If no @ character is found, QUERY will simply display the message.
- If a question mark is included at the end of the response list, QUERY
- will match any character. Don't put a space at the end of the list
- unless you want the <Space> bar to be considered a valid response.
-
- USERTEST.BAT:
- echo off
- cls
- query Do you want to see a list of files? @yn
- if errorlevel 2 goto no
- if errorlevel 1 goto yes
- :no don't show list of files
- goto end
- :yes do show list of files
- dir
- goto end
- :end
-
- -----------------------------------------------------------------
- Batch Line Skipper
- (PC Magazine Vol 5 No 3 Feb 11, 1986 User-to-User)
-
- The DOS 3.1 COMMAND.COM patch to skip a line in a batch file with
- the ECHO + space + space construction (User-to-User, Vol 4 No 24) is
- useful only when running a batch file on a system that has the patched
- COMMAND.COM. Anyone else who distributes batch files needs a way to
- skip lines in batch files on all systems. With ECHO OFF, the
- construction ECHO ^H (^H means hold down the Ctrl key and hit the H
- key) will skip a line using both DOS 2.1 and 3.1. To demonstrate this,
- create a batch file called LINE.BAT with these lines:
-
- ECHO OFF
- ECHO This is line 1.
- ECHO ^H
- ECHO This is line 3.
-
- To insert the Ctrl-H you will need an editor or word processor that is
- able to embed control characters. This can be done with WordStar by
- holding down the Ctrl key and typing PH. Using EDLIN this can be done
- by holding down the Ctrl key and typing VH.
- Editor's Note: The extended ASCII character set offers three
- blanks -- CHR$(0), CHR$(32) and CHR$(255). CHR$(32) is the conventional
- between-word space, while CHR$(0) is a null and CHR$(255) is a high-bit
- space. Following ECHO with either a CHR$(0) or a CHR$(255) will skip a
- line. Two other ways to create these line skippers are in BASIC and in
- DEBUG. WordStar lets you make the ECHO + CHR$(255) (but not CHR$(0))
- by holding down the Alt key, typing 255 on the number pad (not the top
- row), and then releasing the Alt key -- if you do this, a ^ appears.
- If you use DEBUG, type in the whole file using your word processor (or
- even the DOS COPY CON: facility) but put a single dummy character where
- the CHR$(0) or CHR$(255) goes. Then get into DEBUG and replace the
- dummy character with either a 0 for CHR$(0) or an FF for CHR$(255), or
- just follow ECHO with a period -- and no intervening space.
-
-
- -----------------------------------------------------------------
- REMless REMs
- (PC Magazine Vol 5 No 3 Feb 11, 1986 User-to-User)
-
- Well-chosen remarks within a batch file can be very valuable in
- prompting a user to swap disks or to display a title or logo. However,
- it would be nice to eliminate the actual word REM from the display.
- The trick is to place a string of backspaces (CHR$(8)) at the beginning
- of the remark line. You can't do this when using the DOS COPY CON:
- batch creation method, since DOS uses the Backspace key for making
- corrections. But any word processor that allows embedded control codes
- makes it easy.
- In the following REMLESS.BAT example, the first remark will be
- preceded by a REM, while the second won't. (Each backspace here
- appears as a lowercase h.)
-
- CLS
- REM this is a remark
- REMhhhthis is a REMless remark
-
- You can also use this technique along with SideKick's ability to enter
- and edit the upper 128 ASCII graphics symbols to create attractive
- titles.
- Editor's Note: This eliminates the problem of displaying REMs,
- but it's just as easy to start batch files with ECHO OFF and then ECHO
- comments. If you have a word processor such as SideKick or WordStar
- that lets you embed control characters, you can create each backspace
- in REMLESS.BAT by typing Ctrl-PH (they'll show up as ^H's). Otherwise,
- run the REMLESS.BAS program below.
-
- 100 'REMLESS.BAS: Creates REMLESS.BAT test batchfile
- 110 OPEN "remless.bat" FOR OUTPUT AS #1
- 120 PRINT #1,"CLS"
- 130 PRINT #1,"REM this is a remark"
- 140 PRINT #1,"REM";STRING$(3,8);"this is a REMless remark"
- 150 CLOSE:END
-
-
- -----------------------------------------------------------------
-
- Improved Return to a Previous Directory
- (PC World January 1986 The Help Screen)
-
- This technique provides a more elegant method to make a batch file
- that changes directories switch back to the directory from which the
- batch file was invoked. It assumes that batch files are kept in a
- directory called BATCH and that a PATH command that includes the BATCH
- directory is executed by the hard disk's AUTOEXEC.BAT file.
- This routine relies on a 3-character ASCII file called CDSPACE.TXT
- and three DOS commands that you can add to any batch file that changes
- directories. First create CDSPACE.TXT and store it in the hard disk's
- BATCH directory with the following procedure. At DOS, type COPY CON C:
- \BATCH\CDSPACE.TXT and press Enter. Then type CD and press the space
- bar. To write the file to disk, press F6 and Enter.
- After creating SAMPLE.BAT below, type PATH and press Enter to
- verify that C:\BATCH is included in the list of directories that are
- to be searched for the commands or batch files not in the current
- directory. (If it is not included, type PATH C:\BATCH and press
- Enter.) Make the root directory current by typing CD\ and press
- Enter, and run the batch file by typing SAMPLE followed by Enter.
- The first line of SAMPLE.BAT copies the 3-character ASCII file
- CDSPACE.TXT into a file called RESET_CD.BAT in the BATCH directory of
- drive C:. The ">NUL" at the end of this line redirects the screen
- output of the copy command, "1 file(s) copied," to the NUL device
- (the equivalent of "nothing") so that the copy message is not displayed
- on the screen. The double greater-than symbols in the second line
- cause the CD (current directory) command's output (in this case,
- C:\), which is normally displayed on screen, to be appended to the 3
- characters of RESET_CD.BAT. RESET_CD.BAT now consists of the command
- CD followed by the name of the directory from which SAMPLE.BAT was
- invoked. These two lines, of course, must be executed before the
- batch file changes directories. SAMPLE.BAT then displays the current
- directory (the directory from which it was invoked), changes
- directories, and displays the name of the new current directory. The
- last line of SAMPLE.BAT calls RESET_CD.BAT, the file that was created
- by SAMPLE.BAT's first two lines. RESET_CD.BAT makes the directory
- from which SAMPLE.BAT was called the current directory.
-
- SAMPLE.BAT:
- COPY C:\BATCH\CDSPACE.TXT C:\BATCH\RESET_CD.BAT > NUL
- CD >> C:\BATCH\RESET_CD.BAT
- REM The lines that begin and end this sample batch
- REM file can be added to any batch file that changes
- REM directories so that the batch file can change
- REM back to the directory from which it was invoked.
- CD
- CD \BATCH
- CD
- RESET_CD
-
- -----------------------------------------------------------------
- Batch Refinements
- (PC Magazine Vol 5 No 6 Mar 25, 1986 User-to-User)
-
- You can speed up execution of batch files two ways. First,
- instead of using repeated ECHO statements to put long messages
- on-screen, have the program instead TYPE the contents of several small
- message files on the same disk. This also lets you create attractive,
- centered screens with borders, arrows, etc. Second, instead of using
- REMs to insert nonprinting comments, turn such comments into labels by
- putting a colon at the beginning of the line. These look neater than
- REMs and will not print to the screen regardless of whether ECHO is
- off or on.
- All FOR DOS Redirection
- (PC World April 1986 The Help Screen)
-
- This article addresses execution of the DOS command FOR with a
- utility that requires redirection fo standard input and output.
- Suppose the utility STRIP.COM is used to convert WordStar files
- into ASCII files. The command syntax is STRIP < infile > outfile
- where infile is the name of the WordStar file to be converted, and
- outfile is the name of the ASCII output file. The command:
- FOR %Z IN (*.*) DO command will execute whatever DOS command replaces
- command for each of the file names listed between the parentheses.
- In using the FOR command to execute STRIP repeatedly for each WordStar
- file (none of which has a file name extension) to create ASCII files
- with the same name plus the extension .ASC, the command:
- FOR %Z IN (*.) DO STRIP < %Z > %Z.ASC produces the "File not found"
- error message.
- The solution: When present in a DOS command, the redirection
- symbol < enables the command to receive its input from the file (or
- device) specified after the symbol instead of from the keyboard.
- In such instances, DOS verifies that the specified file exists before
- executing the command. For example, try the command: DIR < %Z. %Z
- is the name of the file that DOS could not find when you invoke the
- FOR command. Because the FOR command is not executed until DOS has
- completed its search for the input file, %Z is not interpreted as a
- DOS variable but rather as literal characters of a file name, i.e.,
- the redirection symbols in: FOR %Z IN (*.) DO STRIP < %Z > %Z.ASC
- are part of the FOR command and not the STRIP command. To solve the
- problem, first create the STRIP.BAT batch file:
-
- STRIP < %1 > %1.ASC
-
- Substituting STRIP.BAT %Z in place of STRIP < %Z > %Z.ASC in the
- original command works almost as intended, except that conversion
- will work only on the first matching file before the DOS prompt
- reappears. This is because DOS doesn't permit a batch file to be
- nested within a FOR command (or inside another batch file), so control
- is not returned to the FOR command after the nested batch file has
- been executed. You can, however, nest a call for another command
- processor. When the second command processor has completed its
- function, control is passed back to the initial command processor,
- which then resumes its current task. Having created STRIP.BAT,
- therefore, you can type: FOR %Z IN (*.) DO \ COMMAND /C STRIP.BAT %Z
- and press Enter to convert the files. Better yet, place that command
- in a batch file, which you may want to call BULKSTRP.BAT. And don't
- forget that the variables of a FOR command in a batch file must be
- preceded by double % signs.
-
- -----------------------------------------------------------------
- Batch of Documentation
- (PC World April 1986 Star-Dot-Star)
-
- As utility programs accumulate, there's an obvious need for some
- means to keep track of their various features and commands. You can
- maintain the information you need in separate files, one for each
- program. Each program is named after the program it documents, but
- contains the extension .DOC. For retrieval use a batch file called
- DOC.BAT that includes the following line: TYPE %1.DOC | MORE. The
- MORE command prevents text longer than 24 lines from scrolling off
- the screen but requires that the DOS filter program MORE.COM also be
- on the disk; you may choose to omit the command and the pipe symbol
- that precedes it. Whenever you need information about a particular
- utility, simply type DOC followed by the program's name. For example,
- type DOS WHEREIS to view on-line documentation for WHEREIS.COM.
-
- -----------------------------------------------------------------
- Best Batch Branch
- (PC Magazine Vol 5 No 8 Apr 29, 1986 User-to-User)
-
- Long batch files containing numerous "if ... goto" conditional
- statements tend to slow down dramatically as processing moves further
- along. DOS searches slowly for each new label from the top of the
- file, yielding a pathetic 5- to 10-second delay, even on an AT, if
- the label occurs near the end of a long batch. There is a way to get
- rid of all the labels and "if errorlevel ... goto" statements, allowing
- a batch file to work at top speed and still contain numerous
- conditional branches.
- Most batches can be controlled with a simple Y(es) or other
- single-key response to each request. The GETKEY technique described
- in an earlier User-to-User sets a different errorlevel for every
- response. Because DOS returns a "true" if errorlevel <= the set
- value, batch files ordinarily require four "if errorlevel" tests to
- obtain "true" on Y or y but "false" on other keys.
- GETYES.COM performs these tests, thereby removing them from the
- batch. It sets errorlevel 255 for Y or y and errorlevel 0 for any
- other key. This lets you directly perform an operation with the
- statement "if errorlevel 255 (perform some DOS function)". GETYES.COM
- is created with GETYES.BAS below.
- You can next "if" conditionals on one line of a batch file for
- further flexibility and control; for example, "if errorlevel 255 if
- exist filename (perform some DOS function)" or "if errorlevel 255 if
- x == %1 (perform some DOS function)". This doesn't seem to be
- documented in the DOS manual.
-
- 100 'GETYES.BAS
- 110 OPEN "GETYES.COM" AS #1 LEN=1
- 120 FIELD #1,1 AS D$
- 130 FOR B=1 TO 18
- 140 READ A$:LSET D$=CHR$(VAL("&H"+A$))
- 150 PUT #1:NEXT:CLOSE
- 160 DATA B4,00,CD,16,3C,59,74,04,3C
- 170 DATA 79,75,02,B0,FF,B4,4C,CD,21
-
- Editor's Note: This technique makes batch branching a pleasure.
- If you want to use N and n rather than Y and y to trigger errorlevel,
- substitute 4E for 59 in line 160 and 6E for 79 in line 170, and change
- the reference from GETYES.COM to GETNO.COM. To test this after
- creating the GETYES.COM program, use this TESTTHIS.BAT file:
-
-
-
- echo off
- :start
- echo Hit y or Y or another key
- getyes
- if errorlevel 255 goto :yes
- goto :no
- :yet
- echo ...you said yes
- goto :continue
- :no
- echo ...you didn't hit y or Y
- :continue
- echo Now, want to quit (y/n)?
- getyes
- if errorlevel 255 goto :exit
- goto :start
- :exit
-
- The nesting abilities allow even more power. To test these,
- revise the fifth line of TESTTHIS.BAT to read:
-
- if errorlevel 255 if Z==%1 goto :yes
-
- Then, if you execute TESTTHIS.BAT again, hitting Y or y at the first
- prompt will not result in a branch as it did earlier. To make both
- of the nested conditions true, instead of executing the batch file by
- typing TESTTHIS, at the DOS prompt type:
-
- TESTTHIS Z
-
- and hit Y or y when asked. The Z after the filename will replace the
- %1 parameter, and since both conditions (the errorlevel and the Z==Z)
- are true, the batch file will work as advertised. If you try this, be
- sure to type in a capital Z; DOS, which much of the time converts
- lowercase keyboard inputs into uppercase ones, is case-sensitive here.
-
- -----------------------------------------------------------------
- Automating a DOS 3.1 Upgrade
- (PC Magazine Vol 5 No 10 May 27, 1986 PC Tutor)
-
- One of the differences between DOS 3.0 and 3.1 is the way the ECHO
- command works. With DOS 3.0, batch files can turn ECHO off and then
- use the ECHO command to display instructions on the screen. Using ECHO
- followed by two spaces to create blank lines works with DOS 3.0 but
- DOS 3.1 gives an "Echo is off" message on these lines.
- This obstacle can be overcome. Converting batch files is an easy
- job using the search-and-replace function in many text editors and word
- processors. This conversion is an excellent example of a job you can
- handle rather elegantly using only normal DOS programs and facilities.
- The secret is getting ECHO to print a blank line is to use the
- ASCII code 255 instead of a blank. ASCII 255 shows up as a blank on
- the PC screen, but to DOS, it's a nonblank, so you won't get the "Echo
- is off" message. You can create an ASCII 255 at your keyboard by
- pressing the Alt key, typing 255 on the number pad, and then releasing
- the Alt key.
- Some text editors and word processors can handle ASCII 255 and
- some can't, but the job can be done easily with EDLIN. EDLIN is tiny
- and fast, and ideal for doing fix-up jobs on text files less than 64K
- in length.
- If you edit the batch files in EDLIN, you can do a search and
- replace to fix up the ECHO command with this EDLIN command:
-
- 1.RECHO <F6>ECHO {255}
-
- The first number means "start a line 1." The missing second
- number after the comma means to end at the last line in memory. Next
- is R for "replace," followed immediately by the old string (ECHO and
- two blanks). After the old string, press the F6 key (do not type the
- < and > brackets). It will appear on the display as a ^Z. Then type
- the new string: ECHO followed by a blank followed by the ASCII code
- 255. The notation here means: press the Alt key, type 255 on the
- number pad, then release the Alt key. This, incidentally, will appear
- as a blank on your display. Since EDLIN's search and replace is case-
- sensitive, you'll probably have to do it for lowercase "echo" commands
- if you've also used these in your batch files.
- Since EDLIN gets keyboard input through DOS (unlike most word
- processor and text editors), it can be used with redirection of
- standard input. Begin by creating a small file (with EDLIN, of course)
- called REPLACE that looks like:
-
- 1.RECHO <F6>ECHO {255}
- 2.RECHO <F6>Echo {255}
- 3.RECHO <F6>echo {255}
- E
-
- Don't type these lines as commands in EDLIN. Instead, go into
- EDLIN's Insert mode (with the I command), and type them as data into
- the file. These are keystrokes used below. Note that three different
- search-and-replace strings are included for the three possible ways
- ECHO probably appears in your batch files. The E command at the end
- tells EDLIN to end and save.
- (If you ever have to edit REPLACE after you create it, use the /B
- option with EDLIN. Since F6 is the same as a Ctrl-Z, which normally
- means "End of File," EDLIN will stop reading the file at the first
- Ctrl-Z unless it has the /B flag.)
- Now to change a particular batch file, all you have to do is
- enter the command:
-
- EDLIN batfile.BAT < REPLACE
-
- and DOS will get all the keystrokes from REPLACE to do the search and
- replace for you.
- Let's go a step further. Start by creating a one-line batch file
- (called CHGBAT.BAT):
-
- EDLIN %1 < REPLACE
-
- Then create another one-line batch file called CHGALL.BAT:
-
- FOR %%X IN (*.BAT) DO COMMAND /C CHGBAT %%X
-
- Now when you run CHGALL.BAT, it will execute CHGBAT.BAT for every
- batch file on the disk (or subdirectory). Each time CHGBAT runs, it
- loads another batch file into EDLIN and uses REPLACE for the keystrokes
- to do the search and replace.
- An interesting side-effect you'll encounter when you go through
- this process is that some batch files will get edited twice. The
- reason is that EDLIN renames the old version of an edited file with
- an extension .BAK. It creates a new directory entry to save the new
- version. Thus, the FOR command in CHGALL.BAT comes across the file
- again. You'll also notice that CHGALL.BAT and CHGBAT.BAT will
- themselves be edited by EDLIN during this process. Neither of these
- two peculiarities caused any problems under DOS 3.1, however.
- If you have batch files in a lot of different subdirectories on
- your hard disk, you could use SWEEP.COM (PC Mag Vol 4 No 23) to run
- CHGALL over all subdirectories on the hard disk with the command:
-
- SWEEP CHGALL
-
- If you decide to do this, make sure to set your PATH command so
- that DOS can find CHGALL and CHGBAT from different subdirectories.
- Also modify CHGBAT.BAT to include the specific directory where REPLACE
- may be found.
-
- -----------------------------------------------------------------
- Batch File Input Comment
- (PC World June 1986 Star-Dot-Star)
-
- DOS does not have a batch file facility to accept input from the
- keyboard. If you write batch files frequently, you may have been
- frustrated because then can't prompt the user to supply text that can
- be used as parameters for another operation.
- One solution is KEYLINE.COM, which accepts a line of input from
- the keyboard and stores it in a specified file. With I/O redirection,
- that file can supply the equivalent of typed input for another program;
- if the specified file name ends with .BAT, .COM, or .EXE, it can be run
- without modification.
- To use KEYLINE.COM, type: KEYLINE filename <Enter>. (Be sure to
- type only one space between the command KEYLINE and the name of the
- file that is to store the user's input.) Filename may include a DOS
- path, but be careful. Although KEYLINE.COM will create the specified
- file when it does not exist, the program will erase the current
- contents of an existing specified file before it accepts and stores
- the user's response.
- If for any reason the file cannot be created, KEYLINE.COM will
- set the batch ERRORLEVEL to 1 and exit, so you may wish to rest for
- that value immediately after executing KEYLINE.COM. The batch file
- MENU.BAT demonstrates one way to use KEYLINE.COM.
-
- 1 'KEYLINE.BAS: RUN to create KEYLINE.COM
- 10 DEFINT A-Z:CLS:KEY OFF:DEF FNHEX(X$)=VAL("&h"+X$)
- 20 READ F$
- 30 LOCATE 5,1,1:PRINT "Checking DATA ....";
- 40 SUM-0:READ LN:IF LN<0 THEN 80
- 50 READ H$:IF VAL(H$)<0 THEN 70
- 60 SUM=(SUM+FNHEX(H$))*2:SUM=(SUM\256)+(SUM MOD 256):GOTO 50
- 70 READ CKSUM$:IF SUM=FNHEX(CKSUM$) THEN 40 ELSE GOTO 170
- 80 RESTORE:CLS:READ F$
- 90 LOCATE 5,1,1:PRINT "Press any key except ESC to create ";F$;": ";
- 100 A$=INPUT$(1):PRINT:IF A$=CHR$(27) THEN END
- 110 LOCATE 6,1:PRINT "Working ...";
- 120 OPEN F$ AS #1 LEN=1:FIELD #1,1 AS BX$
- 130 READ LN:IF LN<0 THEN 160
- 140 READ H$:IF VAL(H$)<0 THEN READ CKSUM$:GOTO 130
- 150 LSET BX$=CHR$(FNHEX(H$)):PUT #1:GOTO 140
- 160 CLOSE:PRINT:PRINT F$;" has been created.":END
- 170 PRINT:PRINT "Error in DATA line";STR$(LN);" :"
- 180 PRINT "Check DATA statements.":BEEP:END
- 1000 DATA "a:keyline.com"
- 1010 DATA 1,be,80,00,31,db,8a,1c,46,c6,00,00,46,89,f2,b9,20,-1,1b
- 1020 DATA 2,00,b4,3c,cd,21,72,32,89,c1,be,4f,01,c6,04,80,89,-1,5b
- 1030 DATA 3,f2,b8,0a,0c,cd,21,46,31,db,8a,1c,80,c3,02,c7,00,-1,58
- 1040 DATA 4,0a,1a,fe,c3,87,cb,46,89,f2,b4,40,cd,21,72,0a,b4,-1,a0
- 1050 DATA 5,3e,cd,21,72,04,b0,00,eb,02,b0,01,b4,4c,cd,21,-1,21,-1
-
- MENU.BAT:
-
- echo off
- cls
- echo Enter the command you wish to perform:
- keyline cmd.bat
- echo pause >> cmd.bat
- echo %0 >> cmd.bat
- cmd
-
-