windows - cmd script, How to pass token variable(say %%a) to a call -


this first question please bare.

serverlist= abc,def,xyz,.... each of these items comma seperated list b=apple,ball,cat...

i have batch script has nested loop following

 setlocal enabledelayedexpansion  %%a in ("%serverlist:,=" "%") (  /f "delims= " %%b in ( xxxxxxx) (    echo %%~a  echo b %%~b  call :header %%a %%b  echo --------  )  )   :header  (  echo inside header values  %1 %2   ) 

output:

---------------------------------------------  abc  b apple,ball,cat  inside header values "abc" apple  --------  def  b apple,ball,cat  inside header values "def " apple  -------- 

i need complete list of b in :header process further. of getting first element of b in call.

putting formal answer comments:

  1. if arguments batch subroutine have spaces or commas, should quote arguments when call subroutine: call :header "%%a" "%%b".

  2. (thanks aschipfl) within subroutine, unquote arguments processing, use %~1 , %~2. can find out more variable manipulation @ ss64's syntax section, pages on variables, delayed expansion, , substrings.

  3. (thanks lotpings) protect subroutines; before entry point, put unconditional goto prevent execution "falling into" routine.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -