Wait for process to end and continue code in CMD/BATCH -


i trying wait process end, can't use "start /w" because process opens program.

so in all, need kind of scanner if process in waitsession , continue code killsession

@echo off color 02 cd /d c:\windows\system32 timeout -t 1  ***waitsession*** (wait process end) mightyquest.exe  ***killsession*** taskkill /f /im publiclauncher.exe taskkill /f /im awesomiumprocess.exe 

thanks

this should it:

@echo off color 02 cd /d c:\windows\system32 timeout -t 1  set tempfile="%temp%\%random%.txt"  :waitsession rem fetch current process list. store in temp file easy searching. tasklist > %tempfile%  rem reset process "flag" variable. set "process="  rem check process target name searching task list target process name. rem if output returned, put process "flag" variable. /f "usebackq tokens=1 delims=-" %%a in (`findstr /i "mightyquest.exe" %tempfile%`) set process=%%a  rem if nothing returned, means process isn't running. if "%process%"=="" goto killsession  echo process still running.  rem wait , try again. timeout /t 20 goto waitsession  :killsession taskkill /f /im publiclauncher.exe taskkill /f /im awesomiumprocess.exe  rem cleanup. del %tempfile% > nul 

the idea here keep polling active task list , when target process found, delay few seconds , try again.

once not found in task list, jump killsession steps.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -