我有以下 bat 文件 mybat.bat :
1) 停止服务
2) 删除一些日志文件
3)再次启动服务:
@echo off
net stop "myservice"
if ERRORLEVEL 1 goto error
exit
:error
echo There was a problem...maybe it was alreay stopped
rem sometimes the terminal simply closes when trying to delete the logfiles :-(
set folder="C:\stuff\logs"
del %folder%\*.* /s /f /q
net start "myservice"
if %errorlevel% == 2 echo Could not start service.
if %errorlevel% == 0 echo Service started successfully.
echo Errorlevel: %errorlevel%
我手动打开一个 cmd.exe 实例并运行 mybat.bat 但有时它会在尝试删除日志文件时简单地关闭,而 stuff\logs 的内容没有被删除。关于为什么会发生这种情况以及即使删除失败如何使 cmd 实例保持活动状态的任何想法?
如果我等待某个时间并再次执行 mybat 它通常可以工作。