Basically, the script below can be used in three different ways: call foo
.bat boot_up "path"
.bat halt "path"
.bat ssh "path" "command"
I cannot guarantee that the path or the command does not have spaces.
When I use foo.bat for executing my subroutine ssh
, then everything works. Instead, when I try to call my subroutines boot_up
or halt
, an error apprears:
( was unexpected at this time.
But, if I add a third argument to boot_up
or halt
, then everything works again.
So my question is, how do I manage call of batch files with variable lenght of arguments?
:main
echo Argument 1: (%1)
echo Argument 2: (%2)
echo Argument 3: (%3)
call :set_cygwin_env || exit /b 1
if not "%1"=="" if not %2=="" (
if "%1"=="boot_up" (
call :boot_up %2
) else if "%1"=="halt" (
call :halt %2
) else if "%1"=="ssh" if not %3=="" (
call :ssh %2 %3
) else (
call :show_help || exit /b 1
)
) else (
call :show_help || exit /b 1
)
:exit