After reading several answers, I learned a couple of things with experimentation:
files ending with CMD vs BAT will be handled slightly differently.
I was trying to run with silentCMD.exe but the problem is that silentCMD would always wait until any started program finished running before reporting task as being completed....even if the CMD window quit ahead of time.
using move nul 2>&0
does seem to work, but the exit code is never delivered properly. so when using task scheduler, it may have weird results unless you can somehow detect the exact weird result and workaround it.
Solution was to just run the task scheduler (or bat/cmd script) directly without using silentCMD to launch it.
With .BAT
file extension
@echo off
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
taskkill /IM "Program.exe" /T /F
start "" "C:\Program.exe" /arg1 /arg2
TIMEOUT /T 2 /NOBREAK
EXIT /B
The if not "%minimized%"=="" goto :minimized
portion is to launch the bat (or cmd) minimized. difficult to get CMD window to be silent, so this is the next best thing.
BAT
files seem to just exit properly without having to do anything extra.
If using .CMD
file extension
@echo off
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
taskkill /IM "Program.exe" /T /F
cmd /c start "" "C:\Program.exe" /arg1 /arg2
TIMEOUT /T 2 /NOBREAK
EXIT /B
You must use the cmd /c
before the start
in order to get the script to close after the launch.
"C:\Program Files (x86)\Xming\Xming.exe"
a parameter from putty.exe, or an seperate command?