Calling function from included batch file with a parameter

前端 未结 3 1235
庸人自扰
庸人自扰 2021-01-14 07:15

In my main batch file I include another batch file and want to call a function defined in there, code looks like following:

@echo off
call define_wait.bat

i         


        
3条回答
  •  清歌不尽
    2021-01-14 08:19

    Working function bat that forwards it's parameters to it's subfunction:

    @echo off
    call %*
    goto :EOF
    
    :WAIT_AND_PRINT
    set /a time=%1
    for /l %%x in (1, 1, %time%) do (
        ping -n 1 -w 1000 1.0.0.0 > null
        echo|set /p=.
    )
    goto :EOF
    
    :WAIT
    set /a time="%1 * 1000"
    ping -n 1 -w %time% 1.0.0.0 > null
    goto :EOF
    

    In the main bat I now don't include the batch file anymore but call it directly like following:

    call define_wait.bat :WAIT_AND_PRINT 5
    

提交回复
热议问题