Gracefully trap error on dos start cmd

Posted by diehlted on Stack Overflow See other posts from Stack Overflow or by diehlted
Published on 2010-06-07T16:41:52Z Indexed on 2010/06/07 17:02 UTC
Read the original article Hit count: 258

Filed under:
|
|

On a cmd prompt or bat file, I issue the following:

start textpad myfile.txt  and it works fine.

If the program textpad does not exist on the computer, then an error sound and a popup occurs which the OK button must be pushed.

I desire to trap this error so that I could do something like

start textpad myfile.txt || start notepad myfile.txt

where the || implies that if the start of textpad is not successful, then the start of notepad should occur. HOWEVER, I still get the error sound and requirement of hitting OK. My intent is to avoid the sound and the requirement of any user intervention.

I have also tried the following bat approach below, to no avail.

start textpad 
if not %ERRORLEVEL% == 0 GOTO END
start notepad
:END

Any help would be great.

thanks

ted

© Stack Overflow or respective owner

Related posts about batch

Related posts about cmd