If file is exited
Posted: 07 Jun 2010 19:32
Is there a way to check if a batch file is closed out of?
Code: Select all
@echo off
for /f "tokens=1" %%a in ('tasklist /nh /fi "windowtitle eq My Cool Cmd Window Title" 2^>nul') do (
if "%%a"=="cmd.exe" echo Running
)
Code: Select all
@echo off
title EXAMPLE
pause
Code: Select all
@echo off
REM loop while example.bat is not running
:loop1
tasklist /nh /fi "windowtitle eq EXAMPLE" 2>nul |findstr /l "cmd.exe" >nul || (
ping -n 2 localhost>nul
goto :loop1
)
REM loop while example.bat is running
:loop2
tasklist /nh /fi "windowtitle eq EXAMPLE" 2>nul |findstr /l "cmd.exe" >nul && (
ping -n 2 localhost>nul
goto :loop2
)
REM display a message
echo example.bat is closed
echo.
pause
aGerman wrote:example.batCode: Select all
@echo off
title EXAMPLE
pause
check.batCode: Select all
@echo off
REM loop while example.bat is not running
:loop1
tasklist /nh /fi "windowtitle eq EXAMPLE" 2>nul |findstr /l "cmd.exe" >nul || (
ping -n 2 localhost>nul
goto :loop1
)
REM loop while example.bat is running
:loop2
tasklist /nh /fi "windowtitle eq EXAMPLE" 2>nul |findstr /l "cmd.exe" >nul && (
ping -n 2 localhost>nul
goto :loop2
)
REM display a message
echo example.bat is closed
echo.
pause
Run both batch files, after that close example.bat to display a message on the check.bat window.
Regards
aGerman
sp11k3t3ht3rd wrote:Is there anyway to minimized the check.bat once it starts?
Code: Select all
@echo off&setlocal&@set "tmpVariable="||(set "tmpVariable=1"&start "%~dpnx0" /min cmd /c %0 %*&set "tmpVariable="&goto :eof)
Code: Select all
@echo off
title CHECKER1
set /p op=Type the file name you want to be tested to run. (Omit the file extension and make sure the batch file title is the name you enter.):
REM loop while %op%.bat is not running
:loop1
tasklist /nh /fi "windowtitle eq %op%" 2>nul |findstr /l "cmd.exe" >nul || (
ping -n 2 localhost>nul
echo %op%.bat is not running >>%op%" "log.txt
goto :loop1
)
REM loop while %op%.bat is running
:loop2
tasklist /nh /fi "windowtitle eq %op%" 2>nul |findstr /l "cmd.exe" >nul && (
ping -n 2 localhost>nul
echo %op%.bat is running >>%op%" "log.txt
goto :loop2
)
REM display a message
echo %op%.bat is closed >>%op%" "log.txt
pause