Help with error trapping in autoexec.bat.

Help with error trapping in autoexec.bat.

Post by Matt Wa » Thu, 08 Apr 1993 09:30:10



I am trying to get MSDOS 5.0 to trap an error in my
autoexec.bat.  I do large amounts of zipping and unzipping
since I am the co-sysop on a BBS, and I sometimes have
problems with lost clusters and the like since most of this is
done from within MSWindows.  Example Windows crashes due to
the execution of an unzipped file or from a crash of ARJ,
forced reboot sometimes follows.

Autoexec.bat

c:\win31r\AD_WRAP.COM
SET CPBACKUP=C:\CPBACKUP\DATA
SET TEMP=c:\WIN31r\TEMP

loadhigh C:\CPAV\VSAFE.com /1+/2-/3-/4+/5+/6+/7-/8-
loadhigh c:\mouse\mscmouse /1 /A7
c:\win31r\smartdrv.exe >>nul
loadhigh c:\tools\nde.com
C:\CPAV\BOOTSAFE
Path=C:\CPBACKUP;C:\;C:\WIN31R;C:\DOS;C:\tools\pm;C:\CPAV;C:\WIN31R\SYSTEM;c:\tools\me
prompt $p$g
cls
chkdsk
win

I would like to have a conditional pause or abort from the
batch file if CHKDSK fails.  I have tried a few things with
errorlevel, but they did not work.  Help will be appreciated.

--
                        Matt Ward

                        University of Illinios
                        CCSO

 
 
 

Help with error trapping in autoexec.bat.

Post by Darren Nata » Fri, 09 Apr 1993 05:06:00



>I am trying to get MSDOS 5.0 to trap an error in my
>autoexec.bat.  I do large amounts of zipping and unzipping
>since I am the co-sysop on a BBS, and I sometimes have
>problems with lost clusters and the like since most of this is
>done from within MSWindows.  Example Windows crashes due to
>the execution of an unzipped file or from a crash of ARJ,
>forced reboot sometimes follows.

>Autoexec.bat

>c:\win31r\AD_WRAP.COM
>SET CPBACKUP=C:\CPBACKUP\DATA
>SET TEMP=c:\WIN31r\TEMP
>SET WINPMT=Windows-$p$g

>loadhigh C:\CPAV\VSAFE.com /1+/2-/3-/4+/5+/6+/7-/8-
>loadhigh c:\mouse\mscmouse /1 /A7
>c:\win31r\smartdrv.exe >>nul
>loadhigh c:\tools\nde.com
>C:\CPAV\BOOTSAFE
>Path=C:\CPBACKUP;C:\;C:\WIN31R;C:\DOS;C:\tools\pm;C:\CPAV;C:\WIN31R\SYSTEM;c:\tools\me
>prompt $p$g
>cls
>chkdsk
>win

>I would like to have a conditional pause or abort from the
>batch file if CHKDSK fails.  I have tried a few things with
>errorlevel, but they did not work.  Help will be appreciated.

Here's how I do it:

[stuff]

chkdsk | find "Errors found" > C:\errors.fnd
copy C:\errors.fnd C:\errors.chk > nul
del C:\errors.fnd > nul
if exist C:\errors.chk goto ErrFound
goto NoErrors
:ErrFound
del C:\errors.chk > nul
echo.
chkdsk /f
echo.
:Noerrors

[more stuff]

Replace the chkdsk line in your autoexec.bat file with the above, or make

The above uses the principle that the copy command will not copy 0 byte
files. If no errors are found, then the pipe to find "Errors found" will
create a 0 byte file.

Oh, forgot something--add the line "goto End" (no quotes) before :NoErrors
and add ":End" (no quotes) after [more stuff]. ([stuff] and [more stuff] refer
to your normal autoexec.bat commands).

The above is actually an excerpt from my check.bat . I use a batch enhancer
to call check.bat either once a week or once a month (depending on the
propensity of the computer to generate disk errors). As written above, you
would need to manually run windows from the DOS prompt after any errors are
found.

If you want my entire check.bat and the batch enhancer, drop me a note and
I'll send it (if too many requests, I'll post instead).

'bye

DN

 
 
 

Help with error trapping in autoexec.bat.

Post by Darren Nata » Sun, 11 Apr 1993 00:37:00



>If you want my entire check.bat and the batch enhancer, drop me a note and
>I'll send it (if too many requests, I'll post instead).

I'm going to be away for a week so rather than have people wait I'm posting
now. After re-reading my original follow-up (shown above) I see that I made
a misleading statement about sending the batch enhancer. I meant I would
send a pointer to the enhancer along with the check.bat file. Sorry.

The following is my batch file CHECK.BAT which runs ChkDsk periodically.
If it is time to run ChkDsk, the batch program does so without the /f
parameter (I expect that most of the time there will not be any errors).
If no errors are found, CHECK.BAT ends and returns to the batch file that
called it (autoexec.bat). If errors are found, you will be prompted to
run ChkDsk again, this time with the /f parameter set. Why do it this way?
Because sometimes I'm in a hurry and don't feel like waiting for another
round of ChkDsk. Now that I think about it, why didn't I simply run
ChkDsk /f the first time? Oh, now I remember, because several people
use the same computer, and may be somewhat intimidated by the various
error messages given by ChkDsk with the /f parameter set. For this
reason the option not to do anything is given. If your situation is the
same, you can use the file as given, otherwise simply delete everything
after line 7 "chkdsk | find ..." except the lines "SET GET=" and
"chkdsk /f" .

(My apologies to the original poster who wanted a conditional pause or
escape from his autoexec.bat if chkdsk failed, which I assume means an
error was found--my original lengthy answer to his question was
probably unnecessary, since all that was really needed was to add the
/f parameter to his chkdsk line.)

The example below is set to run ChkDsk once a month. If a once-a-week
frequency is desired, make the following changes:

1) remove line 2 "if exist ..." and line 5 "echo SET MONTH=%GET% ..."
2) change line 3 "GET H 4" to "GET H 1"
3) change line 4 "if %GET%==%MONTH% ..." to "if not %GET%==3 goto Noerrors
4) remove the last line "SET MONTH="

Change number 3) above will cause ChkDsk to run every Wednesday.

For a daily run of ChkDsk that will allow corrections before starting
other programs in the autoexec.bat file, simply remove lines 2 through 7
and the last line.

if exist C:\tools\month.bat call C:\tools\month.bat
GET H 4
if %GET%==%MONTH% goto NoErrors
echo SET MONTH=%GET% > C:\tools\month.bat
echo.
echo Time for the monthly disk errors check . . .
chkdsk | find "Errors found" > C:\errors.fnd
copy C:\errors.fnd C:\errors.chk > nul
del C:\errors.fnd > nul
if exist C:\errors.chk goto ErrFound
goto NoErrors
:ErrFound
del C:\errors.chk > nul
echo.
set GET=
GET NE "Errors were found. Do you want them corrected (Y or N)? "
if %GET%==N goto NoErrors
echo.
chkdsk /f
echo.
:Noerrors
echo.
set GET=
set MONTH=

NOTE:

1) There is no need to create MONTH.BAT since CHECK.BAT creates it for you.
2) You can change the path for MONTH.BAT to anything you wish, as long as
     it exists, and as long as all occurrences of C:\tools\month.bat are
     changed to the same thing.
3) In the batch program shown, the GET program is in a directory in my path.
     You must do the same, or otherwise include the path when running GET
4) MOST IMPORTANT: OBTAIN GET24.ZIP from your favorite ftp site. I found it
     at oak.oakland.edu in pub\msdos\batutl. If you enjoy monkeying with
     batch files, this is certainly an excellent program to have.
5) insert the line "call check.bat" (no quotes) into your AUTOEXEC.BAT file
     in an appropriate position. I put mine before I run Windows since ChkDsk
     should not be run while in the Windows environment. If CHECK.BAT is not
     in a directory on your path, then include the path.

Darren Natale

 
 
 

Help with error trapping in autoexec.bat.

Post by Jen Kilm » Sun, 11 Apr 1993 04:12:57




>>I am trying to get MSDOS 5.0 to trap an error in my
>>autoexec.bat.  I do large amounts of zipping and unzipping
>>since I am the co-sysop on a BBS, and I sometimes have
>>problems with lost clusters and the like since most of this is
>>done from within MSWindows. [deleted]

if you install 6 at some time, you might want to use

chkdsk
if errorlevel 0 if not errorlevel 1 goto next
echo chkdsk errors found, you need to fix them.
goto end
:next

...or you could do a chkdsk /f (but that won't fix any crosslinks).
And sometimes fixing one error causes another. Etc.

-jen

--


 
 
 

1. Moving AUTOEXEC.BAT and Ctrl-C trapping

There are two things that I need for my DOS system.  One of them
is a program that will allow me to specify a different file than
AUTOEXEC.BAT to be run by COMMAND.COM on bootup. I have seen it done,
but the program that did it was password-protected, so I couldn't get
it to work.  It self-destructed after three attempts to use it.

Anyway, if anyone knows of a program or utility that will do this, I
would greatly appreciate knowing about it.  Also, I have a hard drive
partitioned into two logical disks.  Is it possible to make one of
them write-protected while the other remains writable?

Lastly, I have tried trapping Ctrl-C and Ctrl-Break a number of ways.
Can anyone tell me of a program that looks for Ctrl-C, Ctrl-Break,


                        *or*

2. Callback Proceedure

3. Out of Environment space in autoexec.bat error...

4. Where is MSX-DOS2.ROM ?

5. autoexec.bat and understanding bat files

6. Wei?t Du was ein Spannungsteiler oder eine Experte ist?

7. "Too many parameters" error with 200LX path in autoexec.bat

8. Explorer type interfaces

9. * HELP NEEDED DESPERATELY FOR AUTOEXEC.BAT *

10. HELP: msd.exe hangs using my autoexec.bat and config.sys

11. Autoexec.bat, config.sys setup...HELP

12. Help needed for custom autoexec.bat file

13. HELP AUTOEXEC.BAT PUZZEL