You can use WHERE for this and specify the /Q parameter to suppress output and return only the exit code:
WHERE /Q myCommand.exe IF ERRORLEVEL 1 ECHO myCommand.exe not found
If you're including path information, you either need to use the /R parameter or use : to separate the path and file name. These are essentially the same:
WHERE /R "C:\Windows\System32" cmd.exe WHERE "C:\Windows\System32:cmd.exe"
Putting it together based on your question:
WHERE /Q my_command.exe IF ERRORLEVEL 1 ( :: command not found, so don't run it :: maybe show an error message here, can use %ERRORLEVEL% for more information ) ELSE ( :: command exists, so run it with args my_command.exe my_args )
Probably more useful when specifying a path parameter, but when handling a command not found you can use %ERRORLEVEL% for more information. Examples:
| Error Code | Description |
| 1 | Unrecognized command (not found) |
| 2 | Command/file not found in the specified location |
| 3 | Path not found |
| 5 | Access denied |
C:\DOSto be executable with just a basename.