windows - 无法在批处理 scipt 中跟踪文件执行流程
问题描述
`@ECHO OFF
SET logfile="D:\timer.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%
)
`我正在尝试从批处理脚本打开文件 Dashboard.txt 文件,如果它已经打开,我必须关闭第一个实例并打开新的实例。如果我使用循环从批处理脚本跟踪文件关闭,taskkill 和后续命令不起作用。如果我排除循环来跟踪文件关闭,那么我在日志文件中没有得到正确的关闭时间。请建议,我怎样才能保持循环并执行后续命令?
解决方案
推荐阅读
- python - 每次都下载Visual Studio代码python语言服务器?
- c# - 用户单击集合视图时如何显示图像
- php - 该函数只处理最后寻找的模式。怎么了?
- python - 哪个是正确的标准差公式Python
- jelastic - Elasticsearch 容器为空
- ios - 如何在tableview中搜索数据?
- mongodb - 在 .FindOne 的 mongo-go-driver 中创建过滤器
- vba - 作为 ByRef 参数的类属性不起作用
- javascript - JS设置HTML元素的属性
- java - 在没有“WRITE_SETTINGS”权限的情况下单击图像时如何自动增加屏幕亮度