Accessing Batch Functions in another batch file

后端 未结 2 527
礼貌的吻别
礼貌的吻别 2021-02-07 23:09

Alright, so lets say we have a file called \"lib.cmd\" it contains

@echo off
GOTO:EXIT

:FUNCTION
     echo something
GOTO:EOF

:EXIT
exit /b

T

2条回答
  •  攒了一身酷
    2021-02-07 23:17

    Change your lib.cmd to look like this;

    @echo off
    call:%~1
    goto exit
    
    :function
         echo something
    goto:eof
    
    :exit
    exit /b
    

    Then the first argument passed to the batch file (%~1) will identify as the function you want to call, so it will be called with call:%~1, and now you can call it in init.cmd in this way:

    call lib.cmd function
    

提交回复
热议问题