由于%Counter%LSS%Limit%,等待文件程序失败

时间:2014-11-03 20:08:42

标签: windows batch-file cmd

SETLOCAL ENABLEDELAYEDEXPANSION
SET /A Counter = 0
SET /A Limit = 5

:File_Check
IF EXIST D:\Automation\OTOT_OBAL\Automation\myfilter.jar ( 

            GOTO Trigger_Found
            ) 

               ELSE IF %Counter% LSS %Limit% (
                                           timeout /t 5 /nobreak >null
                                           SET /A Counter = Counter + 1
                                           GOTO File_Check
                                             ) 

                     GOTO (VERYEND)


ENDLOCAL

:Trigger_Found
echo ON
echo TRIGGER FOUND
Exit

:VERYEND
echo !Counter!
echo program has reached maximum wait time we are going to exit.
Exit

1 个答案:

答案 0 :(得分:0)

else是多余的,但如果使用必须与前面的)

位于同一物理行

最终goto的目标是标签(veryend),而不是标签veryend


缺少当前代码:

IF EXIST D:\Automation\OTOT_OBAL\Automation\myfilter.jar ( 
 GOTO Trigger_Found
) ELSE IF %Counter% LSS %Limit% (
 timeout /t 5 /nobreak >null
 SET /A Counter = Counter + 1
 GOTO File_Check
) 

GOTO VERYEND

应该有效

IF EXIST D:\Automation\OTOT_OBAL\Automation\myfilter.jar GOTO Trigger_Found
IF %Counter% LSS %Limit% (
 timeout /t 5 /nobreak >null
 SET /A Counter = Counter + 1
 GOTO File_Check
) 

GOTO VERYEND

可能会更好。