[SOLVED] How to pass argument list to function where each argument contains spaces?

Status
Not open for further replies.
Sep 7, 2020
13
0
10
0
Hello! How to pass argument list to function where each argument contains spaces in Batch Script? Here is my code:
Code:
@echo off
    set list="first value" "second value"
    call :p "%list%"
    pause
@echo on
@goto eof

:p
    for %%v in (%~1) do echo %%v
exit /b 0

:eof
I want to obtain:
Code:
first value
second value
output.
 
Last edited:
Sep 7, 2020
13
0
10
0
Answer:
Code:
@echo off
    set list="first value" "second value"
    call :p %list%
    pause
@echo on
@goto eof

:p
    setlocal enabledelayedexpansion
    for %%v in (%*) do (
        set item=%%~v
        echo !item!
    )       
    setlocal disabledelayedexpansion
exit /b 0

:eof
 
Status
Not open for further replies.

ASK THE COMMUNITY