79600199

Date: 2025-04-30 11:14:56
Score: 0.5
Natty:
Report link

A simple solution.

@echo off
:: library.bat

setlocal

:: the name of the function that will be called
set _function_name_=%1

:: the arguments of the function that will be called
set _function_args_=

set _count_=0

:: remove the first argument passed to the script (function name)
for %%f in (%*) do (
    set /a _count_+=1
    if !_count_! GTR 1 set _function_args_=!_function_args_! %%f
)

echo Script args: %*
call %_function_name_% %_function_args_%

endlocal
exit /B


:function1
    echo function name: %_function_name_%
    echo function args: %*
    exit /B


:function2
    echo function name: %_function_name_%
    echo function args: %*
    exit /B

:: examples of use
:: call library.bat :function1 1 2 3 
:: call library.bat :function2 4 5 6 
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: binabik54