cmd批处理文件中调用函数的问题

问题描述

我有一个关于cmd批处理文件调用函数的问题。

根据下面的源代码

如果您想调用 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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...