I have a simple batch file like this:
echo off taskkill /im \"test.exe\" /f > nul pause
If \"test.exe\" is not running, I get this message:
Use this script instead:
@taskkill/f /im test.exe >nul 2>&1
@pause
What the 2>&1 part actually does, is that it redirects the stderr output to stdout. I will explain it better below:
Kill the task "test.exe". Redirect stderr to stdout. Then, redirect stdout to nul.
Show the pause message Press any key to continue . . . until someone presses a key.
NOTE: The @ symbol is hiding the prompt for each command. You can save up to 8 bytes this way.
The shortest version of your script could be:
@taskkill/f /im test.exe >nul 2>&1&pause
The & character is used for redirection the first time, and for separating the commands the second time.
An @ character is not needed twice in a line. This code is just 40 bytes, despite the one you've posted being 49 bytes! I actually saved 9 bytes. For a cleaner code look above.