问题描述
根据下面的源代码:
如果您想调用 REDO/norMAL 函数,当函数结束时,问题是是否可以返回 ECHO copying File... 运行并直到 EXIT( 0)到最后?
谢谢。
源代码
@ECHO OFF
ECHO Checking Network Connection...
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
PING -n 2 192.168.1.1 | FIND "TTL" > NUL
IF errorlevel 1 (
Powershell -nop -c "Write-Host 'ERROR: Failure! Please Check Network Connection! Script Exit!' -BackgroundColor BLACK -ForegroundColor RED"
TIMEOUT /T 1 /NOBREAK > NUL
TIMEOUT /T 5
EXIT(0)
) ELSE (
Powershell -nop -c "Write-Host 'INFO: Success! Network Connected!' -ForegroundColor GREEN"
TIMEOUT /T 2 /NOBREAK > NUL
)
FOR /F %%a IN ('Powershell -nop -c "Get-Date -Format 'HH:mm'"') DO SET time=%%a
IF %time% GTR 12:00 (
GOTO REDO
) ELSE (
GOTO norMAL
)
ECHO copying File...
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
copY "C:\temp\A.csv" "D:\temp\"
ECHO.
ECHO copy Completed!
TIMEOUT /T 1 /NOBREAK > NUL
EXIT(0)
:REDO
ECHO THIS IS REDO FUNCTION
:norMAL
ECHO THIS IS norMAL FUNCTION
解决方法
试试这个:
@ECHO OFF
ECHO Checking Network Connection...
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
PING -n 2 192.168.1.1 | FIND "TTL" > NUL
IF errorlevel 1 (
Powershell -noP -c "Write-Host 'ERROR: Failure! Please Check Network Connection! Script Exit!' -BackgroundColor BLACK -ForegroundColor RED"
TIMEOUT /T 1 /NOBREAK > NUL
TIMEOUT /T 5
EXIT(0)
) ELSE (
Powershell -noP -c "Write-Host 'INFO: Success! Network Connected!' -ForegroundColor GREEN"
TIMEOUT /T 2 /NOBREAK > NUL
)
FOR /F %%a IN ('Powershell -Nop -c "Get-Date -Format 'HH:mm'"') DO SET time=%%a
IF %time% GTR 12:00 (
GOTO REDO
:BACK
) ELSE (
GOTO NORMAL
:BACK
)
ECHO Copying File...
ECHO.
TIMEOUT /T 1 /NOBREAK > NUL
COPY "C:\temp\A.csv" "D:\temp\"
ECHO.
ECHO Copy Completed!
TIMEOUT /T 1 /NOBREAK > NUL
EXIT(0)
:REDO
ECHO THIS IS REDO FUNCTION
GOTO BACK
:NORMAL
ECHO THIS IS NORMAL FUNCTION
GOTO BACK