windows - ikke i stand til at spore strøm af filudvisning i batch scipt

Indlæg af Hanne Mølgaard Plasc

Problem



`@ECHO OFF

SET logfile="D:	imer.txt"
SET accessfile="Dashboard.txt"
ECHO "***********************************************************" >> \%logfile\%
ECHO "Start time \%DATE\% \%Time\%" >> \%logfile\%

if exist D:2018\%accessfile\% goto :labela
if not exist D:2018\%accessfile\% goto :labelb


:labela 
(

Start D:2018\%accessfile\% goto :Runningloop 2>&1 && (

echo "*** Date: \%DATE:/=-\% and Time: \%TIME\% :: Dashboard notepad file opened successfully ***" >> \%logfile\% 

) || ( 
        taskkill /F /FI "WindowTitle eq Dashboard - notepad" /T >> \%logfile\% 2>&1 && (
        Start  Z:\%accessfile\% goto :Runningloop >> \%logfile\% 2>&1 && echo "*** Date: \%DATE:/=-\% and Time: \%TIME\% :: Old instance of file Dashboard is deleted and New instance of file opened successfully ****" >> \%logfile\%

         ) || (  echo "*** Date: \%DATE:/=-\% and Time: \%TIME\% :: Error while closing the current instance of file Dashboard hence unable to Reopen the file   ***" >> \%logfile\% )


)

:Runningloop
(
CLS

set errorlevel=

tasklist /fi "WindowTitle eq Dashboard - notepad" | find /i "notepad.exe"> NUL

if /i \%errorlevel\% GTR 0 goto ClosureOfFile

GOTO Runningloop

)
:ClosureOfFile
(
ECHO.

ECHO "Dashbiard notepad file is closed."  >> \%logfile\%
ECHO "Stop time \%DATE\% \%Time\%" >> \%logfile\%
exit

)

) 
exit /b 


:labelb 
(

echo "*** Date: \%DATE:/=-\% and Time: \%TIME\% :: Failure, File does not exist , Please Check *****" >> \%logfile\%
echo "*** Date: \%DATE:/=-\% and Time: \%TIME\% :: End of Script" >> \%logfile\%
echo "**********************************************************************************************************" >> \%logfile\%

) 


`Jeg forsøger at åbne filen Dashboard.txt-fil fra batch script, hvis den allerede er åben, skal jeg lukke første instans og åbne frisk en.
hvis jeg bruger sløjfe til at spore fillukning fra batch script, taskkill og efterfølgende kommandoer ikke fungerer.
Hvis jeg udelukker sløjfe for at spore fillukning, får jeg ikke korrekt lukketid i logfilen.
bedes du foreslå, hvordan kan jeg holde loop og udføre efterfølgende kommandoer?

Bedste reference