When I use the start command in a batch script to launch a program, I expect that program to be launched asynchronously; this happens exactly as I'd expect it would if the program that I'm launching exists.

However, if I try to start a program that doesn't exist, Windows displays a popup telling me that it cannot find the file, locking up the execution of the batch script until I manually close the popup. This is annoying. Because of some remote filesystem shenanigans, I have no way to reliably guarantee that the binary will exist before I run it, and I have no way to lock the binary. In my scenario, if the binary doesn't exist, it's not a critical error, and my script should just proceed.

Is there a way to prevent these popups from being created in the first place, or alternatively a batch/cmd one-liner that can be used to asynchronously execute applications that won't block the script from continuing if it fails (something I can just as easily use from a CLI as a batch script)?

  • Maybe you can START another bat-script which itself starts the executable without START since in this case, the second shell should just print an error.
    – tkausl
    Jul 25 '15 at 22:27

I have no way to reliably guarantee that the binary will exist before I run it

You can use the which.cmd to see if a binary exists, and returns an appropriate ERRORLEVEL.

Workaround for your issue (Disabling the "Windows cannot find '[foo].exe'" popup)

  • run which program
  • check the ERRORLEVEL
  • run start only if program is found.
:: WHICH.CMD  CommandName  [ReturnVar]
::  Determines the full path of the file that would execute if
::  CommandName were executed.
::  The result is stored in variable ReturnVar, or else it is
::  echoed to stdout if ReturnVar is not specified.
::  If no file is found, then an error message is echoed to stderr.
::  The ERRORLEVEL is set to one of the following values
::    0 - Success: A matching file was found
::    1 - No file was found and CommandName is an internal command
::    2 - No file was found and CommandName is not an internal command
::    3 - Improper syntax - no CommandName specified

The link below includes the full source code for which.cmd (which was written by superuser user dbenham).

Source which.cmd - Show the full path to an executable file.

  • This won't work. I already know how to check for a file's existence, but as it is now, I have no way to verify the files existence reliably because I can't lock the file in the brief interim between checking for it and executing it, and the batch script will be running on a somewhat overwhelmed system. My question is about getting cmd to stop blocking my batch script from executing when failures inevitably occur. Jul 24 '15 at 18:43

One way would be to copy/move the binary file to a new temporary location with a unique name and execute it.
If the copy/move is successful, then the unique file exists and you can execute it without influence from "remote filesystem shenanigans". If not, then at least you know you will not get the pop-up window.

  • 1
    Would you need to use xcopy to get a return value for success? Feb 1 '16 at 14:29

Use the /C switch for the start command, it should skip the annoying popup.

start /C appthatmayfail.exe args

  • I haven't heard of the /C switch before and can't find documentation for it. Can you share your documentation? Feb 1 '16 at 14:27
  • start doesn't have a /c option.
    – DavidPostill
    Feb 1 '16 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.