我有一个脚本可以将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没有启动。这里的问题是什么?
答案 0 :(得分:2)
在这一行中,您省略了一个空格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
答案 1 :(得分:0)
问题是他无法找到tes2.vbs文件。将%tmp%\添加为vbs文件的目录路径!现在它有效。