Hi deusery,
yes you can.
There are different solutions to build a batch library,
but no
perfect one.
1) You can use a HACK/bug/feature of cmd.exe
If you call a label in the same file and then start a second batch file without CALL,
then the label will be jumped to also in the second batch file!
batch1.bat
Code: Select all
echo Start first func in batch2
call :externalFunc1
echo Start second func in batch2
call :externalFunc2
...
exit /b
:: Jump helper function, list all possible labels of batch2 here
:externalFunc1
:externalFunc2
:externalFunc3
batch2.bat
exit /b
But the drawback is the need to duplicate all labels in batch1.
2) You can use Batch-Macros
Pro: Fastest execution time
Contra: Hard to write, hard to debug
3) Trampoline jump
Add this to the beginning of each library
Code: Select all
@echo off
REM *** Trampoline jump for function calls of the form ex. "C:\:libraryFunction:\..\libThisLibraryName.bat"
FOR /F "tokens=3 delims=:" %%L in ("%~0") DO goto :%%L
And to use a function inside a library you call it like:
Code: Select all
call "c:\:myLibFunction:\..\path_to_lib\myLibrary.bat" arg1 arg2 ...
Pro: Very flexible
Contra: The call instruction looks strange and is a bit cumbersome
The CALL's can be simplyfied with the macro technic to something like
Personally, in my own library I'm using a mix of 2) and 3)
jeb