How Can I Trap an error?
Moderator: DosItHelp
-
- Posts: 5
- Joined: 20 Feb 2011 12:39
How Can I Trap an error?
This code is to locate a usb drive that has the program math911.exe. It works fine and locates the usb at drive I: However, just before the echo statement it shows an error message in a pop up window that says:
There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR1
When I remove F and J the popup does not appear because those are the drives
that I do not have. The popup only shows one time. I must press cancel to continue with the batch file.
How can I get the batch file to ignore the error and continue without the pop up?
@Echo Off
Setlocal
For %%a in (D E F G H I J) do (
IF Exist "%%a:\math911.exe" set "drive=%%a:"
)
echo The USB drive is: %drive%
set Pathname=%drive%
cd /d %Pathname%
dir
pause
md auto6
cd auto6
md con\
There is no disk in the drive. Please insert a disk into drive \Device\Harddisk1\DR1
When I remove F and J the popup does not appear because those are the drives
that I do not have. The popup only shows one time. I must press cancel to continue with the batch file.
How can I get the batch file to ignore the error and continue without the pop up?
@Echo Off
Setlocal
For %%a in (D E F G H I J) do (
IF Exist "%%a:\math911.exe" set "drive=%%a:"
)
echo The USB drive is: %drive%
set Pathname=%drive%
cd /d %Pathname%
dir
pause
md auto6
cd auto6
md con\
Re: How Can I Trap an error?
'
If you are running XP 32x or below you may be in luck ( This link will has expired ).
Otherwise you may need to enumerate 'mountvol /?', search dosTips, plenty of topics around.
If you are running XP 32x or below you may be in luck ( This link will has expired ).
Code: Select all
> drvgtact.BAT drvgtact.EXE &call drvgtact.BAT &set drive
-
- Posts: 5
- Joined: 20 Feb 2011 12:39
Re: How Can I Trap an error?
Thanks for your quick reply.
I'll be using various OS not just xp.
I really do not understand your tip.
Are you saying that there is no code (switch?) that I can add to that
will ignore the error and continue executing without the popup message?
I'll be using various OS not just xp.
I really do not understand your tip.
Are you saying that there is no code (switch?) that I can add to that
will ignore the error and continue executing without the popup message?
Re: How Can I Trap an error?
Is the batch file being started from the same USB drive that has your executable you are checking to see if it exists?
Re: How Can I Trap an error?
The 'drvgtact.EXE' program I posted previously is obsolete from XP and up but if the program is started from usb just usethemathprof wrote:I'll be using various OS not just xp.
Code: Select all
echo.%~d0
Code: Select all
@echo off &setlocal enabledelayedexpansion
echo.Currently mounted drives:
set "$=" &for /f "skip=16 tokens=1 delims=\ " %%? in (
'mountVol.EXE'
) do for %%? in ( %%~? ) do set "$=!$!,%%~?"
set "$"
echo.
Echo.These drives are ready and:
for %%? in (
!$!
) do dready.COM %%~? &&if exist "%%~?\*.EXE" (
echo.exists "%%~?\*.EXE"
) else echo.not exists "%%~?\*.EXE"
pause
exit
Code: Select all
Currently mounted drives:
$=,F:,G:,C:,D:,E:,X:,H:,I:,J:,A:,M:,N:,O:,P:
These drives are ready and:
exists "F:\*.EXE"
exists "G:\*.EXE"
not exists "C:\*.EXE"
not exists "D:\*.EXE"
not exists "E:\*.EXE"
not exists "X:\*.EXE"
Druk op een toets om door te gaan. . .
I see, you mean the famous On Error Resume Next no !themathprof wrote:Are you saying that there is no code (switch?) that I can add to that
will ignore the error and continue executing without the popup message?
But what if all the above fails ?
Code: Select all
;Download autoIt compiler, change $title and $text to match the messageBox,
;Compile the script and if it doesn't works, post your question at the autoIT forums.
$title = 'Title:Windows - Geen schijf;Class:#32770'
$text = 'Exception Processing Message c0000013'
If WinWait( $title, $text ) Then
;
$time = 0
While WinExists( $title, $text )
;
If Sleep( $time ) _
And WinActivate( $title, $text ) _
And ControlFocus( $title, $text, Button3 ) _
And ControlClick( $title, $text, Button3 ) _
Then WinWaitClose( $title, $text, 1 )
$time += 1
;
WEnd
;
EndIf
Regards,
Re: How Can I Trap an error?
Came up with this but was also thinking of checking the errorlevel of the pushd command as well. I don't know what that will do with your sdcard drive letters. I have an SDcard reader on my Windows 7 laptop but I don't see the drive letters in My computer until something is put in them so I assume this is a windows xp issue.
Code: Select all
@Echo Off
Setlocal
For %%a in (D E F G H I J) do (
dir %%a:\math911.exe > nul 2>&1 &&set "drive=%%a:"
)
echo The USB drive is: %drive%
set Pathname=%drive%
cd /d %Pathname%
dir
pause
md auto6
cd auto6
md con\
Re: How Can I Trap an error?
'
Why didn't I come up with that
Ah now I remember my solution works for windowsME command.COM
But even there the dir should throw an error, I don't remember
Or would it have asked me PLEASE INSERT DISK:
ABORT, RETRY, FAIL ?
Why didn't I come up with that
Code: Select all
dir a:
Code: Select all
Microsoft Windows XP [versie 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
>dir a:
Het apparaat is niet klaar.
>
But even there the dir should throw an error, I don't remember
Or would it have asked me PLEASE INSERT DISK:
ABORT, RETRY, FAIL ?
Re: How Can I Trap an error?
Well I fired up my XP VM which just has A: C: and D:(dvd drive) and just did a little command line testing.
I didn't get any pop ups with this code but I don't know about sdcard readers.
Code: Select all
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\XPMUser>dir D:\math911.exe > nul 2>&1 &&echo it exists
C:\Documents and Settings\XPMUser>dir a:\math911.exe > nul 2>&1 &&echo it exists
C:\Documents and Settings\XPMUser>dir a:\math911.exe
The device is not ready.
C:\Documents and Settings\XPMUser>
I didn't get any pop ups with this code but I don't know about sdcard readers.
-
- Posts: 5
- Joined: 20 Feb 2011 12:39
Re: How Can I Trap an error?
Squashman,
Your code works!
Brilliant.
Thank you much.
Themathprof.
Your code works!
Brilliant.
Thank you much.
Themathprof.
Re: How Can I Trap an error?
themathprof wrote:Squashman,
Your code works!
Brilliant.
Thank you much.
Themathprof.
Your Welcome.
Re: How Can I Trap an error?
Here is a completely different method to find the drive letter that has the target file in the root directory. No need to provide a list of potential drive letters. I added an extra column so I don't have to worry about the line ending carriage return that FOR /F gets when used with WMIC.
Dave Benham
Code: Select all
@echo off
setlocal
for /f "usebackq skip=1" %%A in (
`wmic datafile where "path='\\' and filename='math911' and extension='exe'" get drive^, extension`
) do (
set drive=%%A
goto :break
)
:break
echo The USB drive is: %drive%
cd /d %drive%\
dir
pause
md auto6
cd auto6
md con\
Dave Benham
Re: How Can I Trap an error?
Dave, that is a thing of beauty!