mirror of
https://github.com/opsxcq/mirror-textfiles.com.git
synced 2025-08-07 05:26:43 +02:00
614 lines
28 KiB
Plaintext
614 lines
28 KiB
Plaintext
|
|
THE BATPOWER FAQ,
|
|
or Frequently Asked Questions
|
|
|
|
*** Last revision: 03 May 96 ***
|
|
|
|
+----------------------------------------------------------------+
|
|
| Table of Contents for | 14. Path over 128 characters |
|
|
| FREQUENTLY ASKED QUESTIONS, | 15. What is the 'MUF'? |
|
|
| (FAQ) for the BATPOWER Echo | 16. Recursion/Loops in a BAT |
|
|
|-------------------------------+ 17. Start-up screen rotation |
|
|
| 1. How to reboot in a BATch | 18. Tidying output from a BAT |
|
|
| 2. Communicate with a modem | 19. Using ANSI codes in a BAT |
|
|
| 3. Date & Time Use in a BAT | 20. REM or :: in a BATch |
|
|
| 4. Combine files into one | 21. Is bat run from Windows ? |
|
|
| 5. Formatting Disks Q&A | 22. Using Ctrl+Z in a BATch |
|
|
| 6. Getting errorlevel Q&A | 23. Zero byte files- questions |
|
|
| 7. Help with making a menu | 24. Banish 'Retry,Abort,Ignore'|
|
|
| 8. Is TSR loaded in memory ? | 25. Getting user BATch input |
|
|
| 9. Jump back to prior dir | 26. BATch Programming Books |
|
|
| 10. Find&Replace text in file | 27. |
|
|
| 11. Low level HD format Q&A | 28. |
|
|
| 12. FOR..IN..DO Q&A's | 29. |
|
|
| 13. Out of Environment Q&A's | 30. |
|
|
+----------------------------------------------------------------+
|
|
|
|
|
|
1. HOW TO REBOOT IN A BATch
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I reboot the PC from inside a batch file ?
|
|
A: ECHO G=FFFF:0 | DEBUG >NUL for MSDOS} these occasionally
|
|
ECHO GFFFF:0000 | SID >NUL for DRDOS} will give garbage
|
|
--------------------------------------------------------------
|
|
ECHO HPSË>REBOOT.COM This seems reliable, most editors
|
|
REBOOT.COM will allow Alt+203 to get the Ë
|
|
Hold the ALT key while 2 0 3 is
|
|
entered at the r/h keypad (Numlock ON)
|
|
--------------------------------------------------------------
|
|
This DEBUG script will produce COLDBOOT.COM when you run it
|
|
------------------------------------+ thus: DEBUG<SCRIPT.EXT
|
|
If your using BNU type: BNU /B |
|
|
If your using XDO type: XU BOOT | N COLDBOOT.COM
|
|
If your using 4DOS type: REBOOT | E 0100 48 50 53 CB 0D 0A
|
|
------------------------------------+ RCX
|
|
Flush your Disk Cache before you use| 0006
|
|
!!!! any of these methods !!!! | W
|
|
for Smartdrive this is: SMARTDRV /C | Q
|
|
|
|
|
|
2. COMMUNICATE WITH A MODEM
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I communicate with my modem either in a BATch or on
|
|
the command-line ?
|
|
A: After setting up the COM port with MODE if required simply
|
|
use DOS redirection > to ECHO AT commands to it.
|
|
E.G. MODE COM1 baud=19200 data=8 parity=n stop=1
|
|
ECHO AT&FF10\N4&D3E0M0Q1S0=1&W0>COM1
|
|
might be used to set up a modem loading a profile into it
|
|
or if you wanted to leave a computer accessible from a
|
|
remote location you might shell out of a communications
|
|
program and run a batch file containing:
|
|
%COMSPEC% /e:1024 >COM1 <COM1
|
|
which would start a copy of the command processor to accept
|
|
input from the remote computer and output to it.
|
|
(with MS-DOS error messages would not get sent but 4DOS
|
|
allows STNDERR device writes to be re-directed)
|
|
|
|
|
|
3. DATE & TIME USE IN A BAT
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I create a LogFile or get the current Time & Date
|
|
into environment variables.
|
|
A: A number of utilities to get the time or date into an
|
|
envar exist, among them are P2E, GET25, BATCHMAN & STRINGS
|
|
but a pure MS-DOS solution exists too:
|
|
VER|TIME|FIND "Current">$$TEMP$$.BAT
|
|
ECHO SET CTIME=%%3>CURRENT.BAT
|
|
$$TEMP$$.BAT
|
|
will place the current TIME into an envar called CTIME and
|
|
TIME can be replaced with DATE above to create CDATE.
|
|
To create a log of system boots the following could be
|
|
inserted into the AUTOEXEC.BAT file:
|
|
ECHO -=-=-=-=-=-=-=-=-=-=-=-=-=-=->>BOOTLOG.TXT
|
|
ECHO System booted !!! >>BOOTLOG.TXT : For more :
|
|
VER|TIME|FIND "Current">>BOOTLOG.TXT : techniques :
|
|
VER|DATE|FIND "Current">>BOOTLOG.TXT : type $ :
|
|
|
|
Using P2E to create filenames in YYMMDD.* format :
|
|
@ECHO OFF
|
|
ECHO.|DATE|P2E /E MM /L 1 /M 21,2 /E DD /L 1 /M 24,2 /E YY /L 1 /M 29,2
|
|
ECHO This is a New File>%YY%%MM%%DD%.TXT
|
|
|
|
Using PROMPT and CALL to create an 'ECHO'able Current Date & Time :
|
|
@ECHO OFF
|
|
ECHO @PROMPT LOG ON: $d at $t$h$h$h>C:\TEMP\TEMP$$$$.BAT
|
|
%COMSPEC% /C C:\TEMP\TEMP$$$$|FIND ":">>C:\LOGONS.TXT
|
|
Typical resultant contents of c:\logons.txt will be:
|
|
LOG ON: Fri 12-27-1993 at 09:37:48
|
|
LOG ON: Tue 01-04-1994 at 08:54:26
|
|
--etc.--etc.--
|
|
The section of the line between @PROMPT and the > is customizable
|
|
and all $codes valid for the PROMPT command can be used as well as
|
|
the current system date and time.
|
|
|
|
|
|
4. COMBINE FILES INTO ONE
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: I have lots of text files that I want to combine into one,
|
|
how can I automate this with a BATch.
|
|
A: The DOS COPY command can be used or redirection of TYPE's
|
|
output as follows:
|
|
COPY *.TXT ALL.XXX
|
|
RENAME ALL.XXX ALL.TXT
|
|
or
|
|
FOR %%f IN (*.TXT) DO TYPE %%f>>ALL.XXX
|
|
RENAME ALL.XXX ALL.TXT
|
|
The renaming of the resultant file is necessary, as when
|
|
it is created by the first COPY or TYPE operation, were
|
|
it called ALL.TXT it would immediately qualify for
|
|
inclusion in the command as it would match the filespec.
|
|
COPY can do binary concatenations too, with the /B param
|
|
MS-Windows remakes WIN.COM everytime Setup is used similar
|
|
to: COPY /B WIN.CNF+VGALOGO.LGO+VGALOGO.RLE WIN.COM
|
|
|
|
|
|
5. FORMATTING DISKS- Q & A
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I format a disk without DOS asking me questions ?
|
|
A: With MS-DOS 3.3 use FORMAT A: /H
|
|
With MS-DOS 4.0+ use FORMAT A: /AUTOTEST
|
|
|
|
!!! BEWARE - THIS WORKS ON HARD DISKS TOO !!!
|
|
|
|
There are a number of other undocumented switches for both
|
|
FORMAT and other MS-DOS features detailed in the MUF.
|
|
(For information about the MUF see item # 15. below)
|
|
|
|
|
|
6. GETTING ERRORLEVELS- Q & A
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I echo the errorlevel returned by a program to the
|
|
screen so I can 'debug' my batch files ?
|
|
A: There are a couple of utilities that can do this but the
|
|
method used for the FAQ is the pure DOS solution below :
|
|
|
|
FOR %%E IN (0,1,2) DO IF ERRORLEVEL %%E00 SET ERLVL=%%E
|
|
IF "%ERLVL%"=="0" SET ERLVL=
|
|
SET RANGE=0,1,2,3,4,5,6,7,8,9
|
|
IF "%ERLVL%"=="2" SET RANGE=0,1,2,3,4,5
|
|
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E0 SET ERLVL=%ERLVL%%%E
|
|
IF "%ERLVL%"=="0" SET ERLVL=
|
|
IF NOT "%ERLVL%"=="25" SET RANGE=0,1,2,3,4,5,6,7,8,9
|
|
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E SET ERLVL=%ERLVL%%%E
|
|
SET RANGE=
|
|
ECHO Errorlevel is %ERLVL%
|
|
|
|
Here is a line-by-line walk thru' of this courtesy Rudy Lachin:
|
|
|
|
FOR %%E IN (0,1,2) DO IF ERRORLEVEL %%E00 SET ERLVL=%%E If errorlevel
|
|
is greater than 0 set ERLVL to 0, if >100 to 1 and if >200 to 2.
|
|
IF "%ERLVL%"=="0" SET ERLVL= If ERLVL=0 clear it (suppress leading 0)
|
|
SET RANGE=0,1,2,3,4,5,6,7,8,9 Now we've set the hundreds check tens
|
|
except when the errorlevel is >200 in which case we only want to go up
|
|
IF "%ERLVL%"=="2" SET RANGE=0,1,2,3,4,5 to the fifties.
|
|
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E0 SET ERLVL=%ERLVL%%%E
|
|
If the errorlevel in this range of tens is above x00 set ERLVL to x00,
|
|
if > x10 set ERLVL to x10, if > x20 set ERLVL to x20, etc.
|
|
IF "%ERLVL%"=="0" SET ERLVL= If ERLVL=0 clear it (suppress leading 0)
|
|
IF NOT "%ERLVL%"=="25" SET RANGE=0,1,2,3,4,5,6,7,8,9 Now we check the
|
|
units except if the errorlevel is 250+ where we only check up to 5 by
|
|
not resetting the RANGE variable contents but re-using it as set above.
|
|
FOR %%E IN (%RANGE%) DO IF ERRORLEVEL %ERLVL%%%E SET ERLVL=%ERLVL%%%E
|
|
If the errorlevel in range of units is above xy0 set ERLVL to xy0, etc
|
|
SET RANGE= Clear the RANGE variable from the environment
|
|
ECHO Errorlevel is %ERLVL% and display the variable ERLVL on screen.
|
|
|
|
|
|
7. HELP WITH MAKING A MENU
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I make a menu system with batch files ?
|
|
A: Here's how you could do it with all BATs in a DIR in your PATH
|
|
|
|
This is MENU.BAT | This is 3.BAT
|
|
@ECHO OFF | @ECHO OFF
|
|
CD\ | CD\
|
|
ECHO MAIN MENU | ECHO GAMES MENU
|
|
ECHO [1] Word Processor | ECHO [31] DooM -Save The Universe!
|
|
ECHO [2] Spreadsheet | ECHO [32] FRAC -Tetris Clone 3D
|
|
ECHO [3] Games | ECHO [33] Return To Main Menu
|
|
ECHO. | ECHO.
|
|
PROMPT Type the number and[ENTER] | PROMPT Type the number and[ENTER]
|
|
-------------+-------------+-------+------+--------------+--------------
|
|
This is 1.BAT|This is 2.BAT|This is 31.BAT|This is 32.BAT|This is 33.BAT
|
|
@ECHO OFF | @ECHO OFF | @ECHO OFF | @ECHO OFF | @ECHO OFF
|
|
CD\WP51 | CD\QPRO | CD\FUN\DOOM | CD\FUN | CD\
|
|
WP51.EXE | Q.EXE | DOOM.EXE | FRAC.EXE | CLS
|
|
MENU.BAT | MENU.BAT | 3.BAT | 3.BAT | MENU.BAT
|
|
|
|
|
|
8. IS TSR LOADED IN MEMORY ?
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How can I test to make sure a TSR like ANSI.SYS is loaded?
|
|
A: All memory-resident programs have to use memory and so an
|
|
output from the MEM /C command will show them resident.
|
|
The BATch below ('hook' needed) illustrates the technique.
|
|
@echo off -----
|
|
if %1'==' goto syntax
|
|
mem /c|find /i "%1">temp.tmp
|
|
copy /b temp.tmp+,, >nul
|
|
if exist temp.tmp echo Program: %1 was found in memory.
|
|
if not exist temp.tmp echo Program: %1 is not loaded.
|
|
if exist temp.tmp del temp.tmp
|
|
goto end
|
|
:syntax
|
|
echo Usage: %0 [TSR to find in memory]
|
|
echo Example: %0 mouse
|
|
:end
|
|
|
|
|
|
9. JUMP BACK TO PRIOR DRIVE / DIRECTORY
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: When I run a program or command how can I get back to the
|
|
directory that was current prior to command execution ?
|
|
A: Several solutions are available as small utilities but
|
|
below is a pure DOS solution.(using environment variables)
|
|
(4DOS has built in variables to deal with this situation)
|
|
|
|
::Set Envars to current drive & current directory
|
|
@echo @prompt SET OLDRV$Q$N$_SET OLDIR$Q$P >TEMP$TMP.BAT
|
|
@command /c TEMP$TMP.BAT > TEMP$$MP.BAT
|
|
@call TEMP$$MP>BAT >nul
|
|
@del TEMP$?MP.BAT
|
|
|
|
Once this BATch has been CALL'd or run:
|
|
%OLDRV% will be evaluated to be the drive when BAT was run
|
|
and %OLDIR% will be evaluated to be the prior directory.
|
|
|
|
|
|
10. FIND & REPLACE TEXT IN FILE
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: Is there a piece of software that does string search and
|
|
replacement from the command line ?
|
|
A: EDLIN (included with MS-DOS) is ideal for this.
|
|
|
|
EDLIN FILENAME.EXT <REPLACE.SCR
|
|
|
|
with the contents of REPLACE.SCR below
|
|
|
|
1,#Rold string^Znew string
|
|
e
|
|
|
|
will replace every occurrence of "old string" throughout
|
|
FILENAME.EXT with "new string"
|
|
|
|
NB Using ^Z (Ctrl+Z) in a BATch is impossible as DOS sees it
|
|
as an End-Of-File marker. Try Rob Flor's ALTER for BATches.
|
|
|
|
|
|
11. LOW LEVEL HARD-DISK FORMATTING
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How can LowLevel Format my Hard-Disk ? I heard you could
|
|
use DOS's DEBUG command, is it true ?
|
|
A: Older styles of drives (mostly MFM style) did have such
|
|
routines situated in a Read Only Memory BIOS chip on their
|
|
controller card. However some controllers had their code
|
|
located at a different memory address to others. Below is
|
|
the command to run this code for the most common types.
|
|
|
|
ECHO g=c800:5|DEBUG
|
|
WARNING !
|
|
Do not try this with Integrated Drive Electronics (IDE)
|
|
type drives and if in doubt - Don't.
|
|
|
|
Some IDE controllers will pretend to LLF, others will just
|
|
hang the PC. It will not even work on ALL MFM type HD's.
|
|
Some IDE's (apparently) can be damaged by attempting this.
|
|
|
|
|
|
12. FOR..IN..DO Queries
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
Q: How does this command work and what's the %%F stuff for ?
|
|
A: The FOR..IN..DO command can be used either in batch files
|
|
where you need to use %%F (two percent signs and variable)
|
|
or at the prompt where only one percent sign is needed.
|
|
In ordinary words the command is "With every member of
|
|
this collection of things do this command". As with most
|
|
DOS commands a little lateral thinking can lead to quite
|
|
complex usage but in its simplest form you could replace
|
|
DIR /B with FOR %F IN (*.*) DO ECHO %F
|
|
(You would need to replace %F with %%F if used in a BATch)
|
|
The %F or %%F is just a temporary variable only active
|
|
while the FOR..IN..DO command is executing, the alphabetic
|
|
character does not have any special meaning, it is just a
|
|
'handle' for DOS to use to pass each member of the set at
|
|
a time along to the DO part of the command. You could run
|
|
all BAT's in sequence with FOR %B IN (*.BAT) DO CALL %B
|
|
|
|
|
|
13. "OUT OF ENVIRONMENT" QUESTIONS
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: Often when I try and run BATch files they don't work and
|
|
I get "Out of Environment Space" error messages, Why ?
|
|
A: The 'environment' is used for variables like %PATH% and
|
|
%PROMPT% and you may need to increase it's size for some
|
|
BATch files that create there own variables to hold data.
|
|
You can increase the size of the primary environment with
|
|
the /E parameter in your SHELL statement in CONFIG.SYS
|
|
E.G. SHELL=C:\DOS\COMMAND.COM C:\DOS /E:2048 /P
|
|
or you could make a temporary adjustment for the BATch
|
|
concerned by starting another copy of COMMAND.COM to run
|
|
it, and specifying a larger environment size for it.
|
|
E.G. %COMSPEC% /E:2048 /C SAMPLE.BAT
|
|
Utilities like STRINGS give you the chance to perform math
|
|
so you could test for adequate environment space in your
|
|
own BAT's, for variables, & then use this method if needed.
|
|
for more details of testing environment space type: !
|
|
|
|
Example of BAT that tests env size for itself using STRINGS
|
|
|
|
@echo off All this BATch does is run a
|
|
STRINGS efree= ENVFREE second copy of itself under
|
|
STRINGS SUB 300, %efree% >nul another copy of COMMAND.COM
|
|
if errorlevel 1 goto DOIT if environment space is less
|
|
STRINGS esize= ENVSIZE than 300 bytes, setting the
|
|
STRINGS esize= ADD %esize%, 300 new environment to 300 bytes
|
|
%comspec% /e:%esize% /c %0 bigger than the current.
|
|
goto END If space is already >or= 300
|
|
:DOIT it jumps to the DOIT label.
|
|
echo We've got 300+ bytes space now!
|
|
echo Environment Size: %esize% ; Environment Free: %efree%
|
|
:END +-----------------------------------------------
|
|
set efree= | With DOS you can check env. space usage with
|
|
set esize= | SET>TEMP.TMP then DIR TEMP.TMP filesize=usage
|
|
|
|
|
|
14. PATH GREATER THAN 128 CHARACTERS
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How can I make my Path bigger than 128 characters long ?
|
|
A: To use more than DOS's command-line limit of 128 chars
|
|
you need to set the PATH in the CONFIG.SYS file (MSDOSv6+)
|
|
or you use an utility like STRINGS or P2E.
|
|
As an alternative you may give sections of a directory
|
|
tree a label as if they were a separate drive. This will
|
|
cut the length of the path statement used for that subdir.
|
|
SUBST K: C:\WINDOWS ( use in AE.BAT before the PATH line )
|
|
|
|
Using P2E: The following line in the Autoexec.Bat will
|
|
set the path to the contents of the mypath.txt textfile.
|
|
P2E Envar PATH <C:\MYPATH.TXT
|
|
|
|
Using STRINGS: The following line in the AE.Bat will set
|
|
the path to the contents of the mypath.txt textfile.
|
|
STRINGS PATH= ASK <C:\MYPATH.TXT
|
|
|
|
|
|
15. WHAT IS THE 'MUF'?
|
|
~~~~~~~~~~~~~~~~~~
|
|
Q: I've been referred to the MUF for an answer or explanation
|
|
to a problem I've posed. What, where, is it ?
|
|
A: The MUF is a list of Microsoft(DOS) Undocumented Features
|
|
It was compiled and edited by Gary Cooper from snippets in
|
|
this echo and from a few other sources.
|
|
Gary has passed the torch to Ron Warder, who will answer in
|
|
the echo, or via FidoNet NetMail at : 1:109/132
|
|
* The MUF is posted occasionally in the BATPOWER Echo, or
|
|
can be obtained from many BBS's as MUF17.ZIP (as of 5-02-96)
|
|
|
|
|
|
16. RECURSION / LOOPS IN A BATCH FILE
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do you do loops in a batch file ?
|
|
And what is recursion / what do you use it for ?
|
|
A: Both loops and recursion can be very useful because like
|
|
other programming languages they can make batch files
|
|
smaller and more effective users of disk space.
|
|
Loops can be either unconditional jumps to a label using
|
|
the GOTO command or by using IF EXIST or IF ERRORLEVEL can
|
|
be made conditional. The BATch running now to show you
|
|
these screens shows both these methods and also shows a
|
|
command that effectively provides looping by performing a
|
|
command for each member of a set of objects. That command
|
|
is: FOR %%[variable] IN ([set]) DO [command]
|
|
Recursion is really just another sort of loop except that
|
|
the batch file actually starts running another copy of
|
|
itself, normally by executing %0 (its name as typed). This
|
|
allows the batch to do work and restart to do more work.
|
|
|
|
|
|
17. START UP SCREEN ROTATION
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: Is there a way to rotate files, so that the same screen
|
|
isn't displayed all the time ?
|
|
A: One method of many available keeps screens in an archive
|
|
until needed with all screens stored in their own subdir
|
|
|
|
:ROTATE
|
|
IF NOT EXIST SCREEN.??? PKUNZIP SCREENS.ZIP
|
|
DEL SCREEN.BBS
|
|
REN SCREEN.??? SCREEN.BBS
|
|
REM done
|
|
|
|
This same method could be used to rotate different BBS
|
|
front screens or to rotate different .BMP or .RLE files
|
|
so Windows wallpaper is rotated for each new session.
|
|
|
|
|
|
18. TIDYING SCREEN OUTPUT FROM A BATCH FILE
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do I stop commands from displaying output on screen ?
|
|
A: Just re-direct their output to the nul device.
|
|
E.G. PAUSE>NUL Will just wait for a keypress before
|
|
continuing, without displaying the usual message:
|
|
"Press any key to continue..."
|
|
To hide error messages as well you'll need to use:
|
|
CTTY NUL
|
|
command that displays error you don't want to see
|
|
CTTY CON
|
|
Be Careful ! While CTTY NUL : the keyboard is ignored !
|
|
|
|
Q: Sometimes when I execute a batch file after running I'm
|
|
left with more than one prompt (as if I'd hit Enter).
|
|
A: This is because the batch file has trailing carriage-
|
|
returns. Use a plain text (ASCII) editor to remove them.
|
|
|
|
|
|
19. Using ANSI (escape codes) in a BATch File
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: I know I need to use an ESC character (Alt+27) to use
|
|
ANSI codes but whenever I try DOS or Editors give me a
|
|
slash or clear the line ?
|
|
A: Use DOS EDIT and press Ctrl+P (which puts you in 'literal'
|
|
mode) and then press Esc and you'll see a small left
|
|
pointing arrow; this is the Esc character. Some editors
|
|
like QEDIT allow you to use the numeric keypad to enter
|
|
the Alt+27 sequence as well (or instead).
|
|
Specialist ANSI screens editors like TheDraw can save you
|
|
a lot of time and are much easier to use !
|
|
To use ANSI in your PROMPT the $e code is an Esc character.
|
|
|
|
If you use 4DOS use lines like the following instead;
|
|
SCRPUT 6 34 BLINK BRIGHT RED ON BLUE W A R N I N G !
|
|
This will write 'W A R N I N G !' in blinking bright red
|
|
on a blue background with the W at row 6, column 34.
|
|
|
|
|
|
20. Using REM or :: (double colons) in a BATch File
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: I heard double colons are better than REM statements, why?
|
|
A: Even though a REM statement is a remark DOS will still
|
|
read the whole line in case it's being re-directed.
|
|
Double colons are seen as an invalid label by DOS when it
|
|
starts to read the line so it skips on to the next line.
|
|
The other way to speed up execution of a batch file that
|
|
has lots of comments is to un-conditionally jump over the
|
|
lines that are comments like this:
|
|
@ECHO OFF
|
|
GOTO START
|
|
This is a comment line that'd slow down the BAT
|
|
So is this line Ú-------------------------
|
|
And so is this one as well | Be careful using double
|
|
:START | colons with 4DOS !
|
|
--continue-with-batch-file-- |::LABEL is a valid label.
|
|
|
|
|
|
21. IS BATCH FILE RUNNING FROM WITHIN WINDOWS ?
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How can I make sure Windows isn't running before I run a
|
|
program in a batch file ?
|
|
A: Either use a purpose-made COM program such as ISWINRUN.COM
|
|
a DEBUG script for which is below, it will exit with 1 as
|
|
ERRORLEVEL if Windows is running , OR use the FIND command
|
|
to look at the output of the MEM /C command to search for
|
|
Windows' 'hook' in memory. If Windows is running in 386Enh
|
|
mode a 'hook' called win386 will be in memory when you are
|
|
in a DOS window. Solutions are outlined below:
|
|
-------------------------------------------------------------
|
|
nISWINRUN.COM
|
|
e100 B8 80 46 CD 2F 3D 0 0 74 2 B0 1 34 1 B4 4C CD 21
|
|
RCX Ú----------------------------------------------------
|
|
12 | MEM /C|FIND "win386">temp.$$$
|
|
W | COPY /B temp.$$$+,,
|
|
Q | IF EXIST temp.$$$ ECHO This is a DOS Window !
|
|
|
|
|
|
22. USING CTRL+Z IN A BATch
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How can you use Ctrl+Z in a batch file, whenever I put one
|
|
in a BATch that's where execution of the BATch stops. ?
|
|
A: This happens because Ctrl+Z is an End-Of-File Marker for
|
|
DOS (EOF). Using EDLIN in a BATch often needs the Ctrl+Z
|
|
to be entered into a script and one of the few ways to do
|
|
this is from the command prompt.
|
|
|
|
Type: SET ZED=(Ctrl+Z) Replacing the bracketed text
|
|
with the real key combination.
|
|
|
|
In BATch files thereafter you can use %ZED% where you are
|
|
required to use a Control+Z key combination.
|
|
|
|
As an example the little batch file below, will search README.TXT
|
|
& replace every instance of 'Marvelous' with 'Wonderful'.
|
|
|
|
ECHO 1,#RMarvelous%ZED%Wonderful>test.scr
|
|
ECHO e>>test.scr
|
|
EDLIN README.TXT <test.scr
|
|
|
|
|
|
23. ZERO BYTE FILES - Questions
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: Does a zero-byte file use a cluster of the disk ?
|
|
A: NO ! However it does use one directory entry and so very
|
|
occasionally should the file be in a subdirectory, the
|
|
entry may need an extra cluster for the directory table.
|
|
|
|
One of the features of zero-byte files is that MS-DOS will
|
|
not copy them so COPY /B filename.ext+,, will delete the
|
|
file if it is zero-byte or if it is not will reset its
|
|
Date/Time Stamp to the system's current settings.
|
|
To create a zero-byte file as a 'flag' use: REM>FLAG.$$$
|
|
Here's an example of how you might use this 'feature':
|
|
CD\
|
|
DIR /B /S|FIND /i "filename.ext">FLAG.$$$
|
|
COPY /B FLAG.$$$+,,
|
|
IF EXIST FLAG.$$$ ECHO filename.ext was found
|
|
IF NOT EXIST FLAG.$$$ ECHO filename.ext is not on drive.
|
|
|
|
|
|
24. BANISH 'Retry, Abort, Ignore'
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How do you intercept DOS's error message that you get if
|
|
you try and print to a printer that's not ready OR when
|
|
you try to read or write to/from an empty drive.
|
|
A: The command line switch for command.com /F will make all
|
|
such situations default to Fail. You can add the /F to your
|
|
SHELL statement in CONFIG.SYS, or you can use it in a .BAT
|
|
as below as a temporary fix for single BATch execution
|
|
|
|
@echo off
|
|
if %1.==. goto END
|
|
echo %comspec% /f /c cprn$$$$.bat>temp$$$$.bat
|
|
echo copy %1 prn: >cprn$$$$.bat
|
|
call temp$$$$.bat
|
|
if exist ????$$$$.bat del ????$$$$.bat >nul
|
|
:END
|
|
echo Usage: %0 [filename to print]
|
|
|
|
|
|
25. GETTING USER BATch INPUT
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
|
Q: How can I get my BATch files to interact with the user ?
|
|
A: Too many utilities have been written, to overcome this
|
|
short-fall in the MS-DOS BATch language, to detail here
|
|
so just some are shown below, with use examples:
|
|
|
|
CHOICE (comes with DOS v6.xx)
|
|
This use of choice nominates valid choices of A&B with a
|
|
default to A after a 20 second wait and gives a prompt
|
|
defined in the quotation marks
|
|
|
|
ECHO *[A] Word Pro.
|
|
ECHO [B] Database
|
|
CHOICE /N /C:AB /T:A,20 "Enter Choice:"
|
|
IF ERRORLEVEL 2 GOTO DATAB
|
|
IF ERRORLEVEL 1 GOTO WORDP
|
|
úúúúetcúúú
|
|
|
|
INPUT (comes with the FAQ)
|
|
INPUT sets the errorlevel to the ASCII value of the
|
|
keypress so EL check is best in 'bracketed' manner shown
|
|
|
|
ECHO Do you want to Quit (Y/N)?
|
|
INPUT 30
|
|
IF ERRORLEVEL 89 IF NOT ERRORLEVEL 90 GOTO END
|
|
IF ERRORLEVEL 121 IF NOT ERRORLEVEL 122 GOTO END
|
|
|
|
|
|
26. BATCH PROGRAMMING BOOKS
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
While the following books have been recommended by various echo
|
|
users, any choice should always be based on your personal
|
|
examination of the book, to ensure that it meets your needs.
|
|
|
|
DOS Power Tools by Paul Somerson
|
|
|
|
Supercharging MS-DOS by Van Wolverton
|
|
|
|
MS-DOS Batch File Programming by Ronny Richardson
|
|
|
|
Advanced MS-DOS Batch File Programming by Dan Gookin
|
|
|
|
Concise Guide to MS-DOS Batch Files by Kris Jamsa
|
|
|
|
=====================================================================
|
|
|
|
The above is a compilation of the information contained in the file:
|
|
BATFAQ11.ZIP, presented in an ASCII text format, and 'updated' as deemed
|
|
necessary, by the moderator, Bat Lang, on 5-03-96. We acknowledge the
|
|
efforts of the many BATPOWER users who contributed to this collection,
|
|
and particularly to our brethren in Zone: 3. This collection, as an
|
|
entity, is the Copyright of the Fido Echo BATPOWER, and should receive
|
|
credit as such. Any of the above, used piecemeal, is considered in the
|
|
Public Domain.
|
|
|
|
Any comments, additions or corrections, should be submitted to the
|
|
moderator, addressed as below.*
|
|
|
|
* Until 14 June 96, such comments should be made in the echo, using the
|
|
Subj: BAT-FAQ.
|
|
|
|
BATPOWER, Moderator
|
|
|
|
NetMail at 1:382/1201 or E-mail: bat.lang@1201.ima.infomail.com
|
|
|