Board logo

标题: [系统相关] 【已解决】bat执行一半自动弹出是否终止批处理 [打印本页]

作者: zhaokeistc    时间: 2015-3-31 11:28     标题: 【已解决】bat执行一半自动弹出是否终止批处理

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set timeDIR=%date:~0,4%%date:~5,2%%date:~8,2%
  4. if exist d:\MobileServer (
  5. set appPath=d:\MobileServer\
  6. set backUp=d:\backUp\
  7. set serviceList=d:\test\
  8. set errorLog=d:\
  9. ) else (
  10. set appPath=e:\MobileServer\
  11. set backUp=e:\backUp\
  12. set serviceList=e:\test\
  13. set errorLog=e:\
  14. )
  15. md %backUp%%timeDIR%
  16. FOR /F %%i in (%serviceList%autoUpdate.txt) do (
  17. for /f "delims=" %%m in ('dir /ad/b "%~dp0"') do (
  18. for /f "tokens=1,2,3 delims=," %%a in ("%%i") do (
  19. set str1=%%a
  20. set str2=%%b
  21. set str3=%%c
  22. if %%m==%%a (
  23. rar a %backUp%%timeDIR%\%%a.rar %appPath%%%m
  24. taskkill /f /t /im %%b
  25. xcopy /y %~dp0%%a %appPath%%%a
  26. sc start %%c
  27. echo %errorlevel%
  28. if errorlevel 1 (
  29. goto loop
  30. )
  31. :loop
  32. sc start %%c
  33. if errorlevel 1 (
  34. echo %%a此文件夹对应的服务启动失败 >>%errorLog%%timeDIR%.txt
  35. )
  36. )
  37. )
  38. )
  39. )
  40. pause
复制代码
在启动服务的时候就会卡住弹出如图      我确定我什么都没按
windows server 2008 r2      的系统          谁知道是为什么啊
作者: zhaokeistc    时间: 2015-3-31 13:26

求大神指导啊
作者: DAIC    时间: 2015-3-31 13:44

完整代码、报错截图,发出来看看。
作者: pcl_test    时间: 2015-3-31 13:46

本帖最后由 pcl_test 于 2015-3-31 13:47 编辑

起码把代码发下吧,什么都没有,怎么帮你检查呢?最好再贴上出错截图
作者: zhaokeistc    时间: 2015-3-31 14:12

回复 4# pcl_test


    以上代码和报错截图
作者: zhaokeistc    时间: 2015-3-31 14:13

回复 3# DAIC


    以上代码和报错截图
作者: zhaokeistc    时间: 2015-3-31 14:18

有时候也会出现
作者: zhaokeistc    时间: 2015-3-31 14:26

大神们呢
作者: DAIC    时间: 2015-3-31 14:29

@echo off
setlocal enabledelayedexpansion
set timeDIR=%date:~0,4%%date:~5,2%%date:~8,2%
if exist d:\MobileServer (
    set appPath=d:\MobileServer\
    set backUp=d:\backUp\
    set serviceList=d:\test\
    set errorLog=d:\
) else (
    set appPath=e:\MobileServer\
    set backUp=e:\backUp\
    set serviceList=e:\test\
    set errorLog=e:\
)
md %backUp%%timeDIR%
FOR /F %%i in (%serviceList%autoUpdate.txt) do (
    for /f "delims=" %%m in ('dir /ad/b "%~dp0"') do (
        for /f "tokens=1,2,3 delims=," %%a in ("%%i") do (
            set str1=%%a
            set str2=%%b
            set str3=%%c
            if %%m==%%a (
                rar a %backUp%%timeDIR%\%%a.rar %appPath%%%m
                taskkill /f /t /im %%b
                xcopy /y %~dp0%%a %appPath%%%a
                REM 1、启动服务之前先用echo命令看看当前获取到的服务是什么,再去检查一下这个服务是否真的存在
                echo 尝试启动服务:%%c
                REM 2、不要在for循环内部定义标签。如果想首次启动失败再次尝试重启的话,这样就行了:
                sc start %%c || sc start %%c
                echo %errorlevel%
                if errorlevel 1 (
                    echo %%a此文件夹对应的服务启动失败 >>%errorLog%%timeDIR%.txt
                )

            )
        )
    )
)
pause
作者: zhaokeistc    时间: 2015-3-31 15:09

回复 9# DAIC


    我查了一下     现在启动服务失败     也经常给我返回0    不知道是为什么
作者: zhaokeistc    时间: 2015-3-31 15:47

ok了    问题已解决   十分感谢
作者: CrLf    时间: 2015-3-31 15:59

好神奇,为毛会自动 ctrl+c 呢




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2