【问题标题】:can't continue script from .bat file after closing msgbox关闭 msgbox 后无法从 .bat 文件继续执行脚本
【发布时间】:2017-09-20 12:27:10
【问题描述】:

我有一个在备份文件夹中保存 2 个文件的脚本。如果复制命令成功与否,我想得到一个消息框。

@echo off
Echo msgbox"Saving test1 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test1.vbs
Echo msgbox"Saving test2 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test2.vbs

copy test1.txt backup\test1.txt
if %ERRORLEVEL% == 0 (
    start test1.vbs
    goto test2
)else (
    echo ## Errorausgabe: %ERRORLEVEL%
    echo.
)

:test2
copy test2.txt backup\test2.txt
if %ERRORLEVEL% == 0(
    start test2.vbs
    goto commonexit
)else(
echo ## Errorausgabe: %ERRORLEVEL%
)

:commonexit
pause

在我从 test1 得到消息框之前它一直有效。但是当我点击提交时,test2 没有启动。这里有什么问题?

【问题讨论】:

    标签: batch-file terminal msgbox


    【解决方案1】:

    在这一行中你省略一个空格if %ERRORLEVEL% == 0( 应该是if %ERRORLEVEL% == 0 ( 并且在这一行中)else ( 应该是) else (

    试试这样:

    @echo off
    Echo msgbox"Saving test1 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test1.vbs
    Echo msgbox"Saving test2 to \backup directory." + vbNewLine + "Successfull!",0,"Backup file..">test2.vbs
    
    copy test1.txt backup\test1.txt
    if "%ERRORLEVEL%" EQU "0" (
        start test1.vbs
        goto test2
    ) else (
        echo ## Errorausgabe: %ERRORLEVEL%
        echo.
    )
    
    :test2
    copy test2.txt backup\test2.txt
    if "%ERRORLEVEL%" EQU "0" (
        start test2.vbs
        goto commonexit
    ) else (
    echo ## Errorausgabe: %ERRORLEVEL%
    )
    
    :commonexit
    pause
    

    https://ss64.com/nt/if.html

    【讨论】:

    • @noags 请再检查一次我编辑我的答案,我测试它的 MsgBox 显示给我!
    • 它在 vbscript 中打印出兼容性问题 .. 他正在等待 test2.vbs 的命令完成
    • @noags 为什么不试试 call 而不是 start?
    • 仍然打开 test1.vbs 但随后在 skript test2.vbs lin1 char 70 处写入错误,问题是:等待指令结束代码 800A0401。
    【解决方案2】:

    问题是他找不到 tes2.vbs 文件。添加 %tmp%\ 作为 vbs 文件的目录路径!现在可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      相关资源
      最近更新 更多