Accessing Batch Functions in another batch file

后端 未结 2 532
礼貌的吻别
礼貌的吻别 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:13

    @echo off
    
    (
    rem Switch the context to the library file
    ren init.cmd main.cmd
    ren lib.cmd init.cmd
    rem From this line on, you may call any function in lib.cmd,
    rem but NOT in original init.cmd:
    call :FUNCTION
    
    rem Switch the context back to original file
    ren init.cmd lib.cmd
    ren main.cmd init.cmd
    )
    

    For further details, see How to package all my functions in a batch file as a seperate file?

提交回复
热议问题