简单的方法是使用 operator:&&
和||
...
@echo off && setlocal EnableDelayedExpansion
cd /d "C:\Program2\VeraCrypt"
(
.\veracrypt.exe /v \Device\Harddisk2\Partition1 /l L /a /p 123xyz /q
) && (
cd /D "D:\backup" & call start_backup.bat
) || (
echo/ something really wrong is going on here....
%__APPDIR__%timeout.exe -1
goto :EOF
)
rem :: continue with more task here.... or goto :EOF
@echo off && setlocal EnableDelayedExpansion
cd /d "C:\Program2\VeraCrypt"
.\veracrypt.exe /v \Device\Harddisk2\Partition1 /l L /a /p 123xyz /q && (
cd /D "D:\backup" & call start_backup.bat ) || (
echo/ Something really wrong is going on here....
%__APPDIR__%timeout.exe -1 & goto :EOF )
rem :: continue with more task here.... or goto :EOF
@echo off && setlocal EnableDelayedExpansion
cd /d "C:\Program2\VeraCrypt"
:loop
set /a "_cnt+=1+0"
(
.\veracrypt.exe /v \Device\Harddisk2\Partition1 /l L /a /p 123xyz /q
) && (
cd /D "D:\backup" & call start_backup.bat
) || (
echo/ something really wrong is going on here....
if "!_cnt!"=="3" (
echo/ Some is really wrong here....
%__APPDIR__%timeout.exe -1 & goto :EOF
) else (
echo/ Let's try +1 times until 3 [!_cnt!/10]
%__APPDIR__%timeout.exe 30
goto :loop
)
)
- 按照@Stephan
if !errorlevel! 0/1 else
的建议使用 30 秒的超时时间进行三次尝试的选项...
@echo off && setlocal EnableDelayedExpansion
cd /d "C:\Program2\VeraCrypt"
:loop
set /a "_cnt+=1+0" && type nul>nul
.\veracrypt.exe /v \Device\Harddisk2\Partition1 /l L /a /p 123xyz /q
if !errorlevel! == 0 (
cd /D "D:\backup" & call start_backup.bat
) else (
echo/ Something really wrong is going on here....
if "!_cnt!"=="4" (
echo/ Some is really wrong here....
%__APPDIR__%timeout.exe -1 & goto :EOF
) else (
echo/ Let's try +1 times until 03 [0!_cnt!/03]
%__APPDIR__%timeout.exe 30
goto :loop
)
)
goto eof 返回到哪里
bat / cmd中的运算符/语法重定向