Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:21:03+00:00 2026-06-15T15:21:03+00:00

I’m trying to extract the batch file argument into 3 strings. I tried first

  • 0

I’m trying to extract the batch file argument into 3 strings. I tried first using a variable then splitting it into 3 (delimiter is a space):

Code:

@echo off
set var=\s v4.12 1,2,3,4
for /f "tokens=1,2,3 delims= " %%a in ("%var%") do (
echo a is %%a, b is %%b, c is %%c
)

Result:

a is \s, b is v4.12, c is 1,2,3,4

But when I tried implementing the var into argument:

New code:

@echo off
for /f "tokens=1,2,3 delims= " %%a in ("%1") do (
echo a is %%a, b is %%b, c is %%c
)

Execution:

test.bat \s v4.12 1,2,3,4

Result:

a is /s, b is , c is

I tried turning on the echo and found out that the argument wasn’t passed in the loop, how do I fix it?

==========
EDIT (this is in response to Aacini’s answer):

My current code:

for /f "tokens=1-3" %%a in ("%*") do (
echo First is %%a, Second is %%b, Third is %%c
:loopers
for /f "tokens=* delims=," %%d in ("%%c") do (
echo %%d
shift
if not  "%%d"=="" (
goto :loopers else exit >nul
)
)
)

After getting the 3rd token (%%c is equal to 1,2,3,4) I have to create a loop again to get each number by using comma as a delimiter but when I tried, it infinitely displays %c (not the value but the actual %c text)

This is the result:

First is /s, Second is v1.4, Third is 1,2,3,4
1
%c
..infinite loop of %c..
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:21:05+00:00Added an answer on June 15, 2026 at 3:21 pm

    Excuse me, I think I don’t understand your question.

    You want to execute this line:

    test.bat /s v1.1 1,3,4,5
    

    and separate parameter in 3 tokens: “/s”, “v1.1”, “1,3,4,5” OR separate parameter in 6 tokens: “/s”, “v1.1” “1”, “3”, “4”, “5” ?

    If you want the first case, then this code do that:

    @echo off
    for /f "tokens=1-3" %%a in ("%*") do (
    echo First is %%a, Second is %%b, Third is %%c
    )
    

    If you want second case, then each parameter is already available in %1 to %6 replaceable parameters:

    echo First is %1, Second is %2, Third is %3, Fourth is %4, Fifth is %5, Sixth is %6
    

    If neither of these solutions are good for you, please explain whay you want in a very concise way! (don’t mix up or put other cases as examples, just put “I want this…”)

    EDIT: New answer as reply to new info

    Please, you must realize that I can not understand what you want reviewing examples. Because you have not said what you want I can only guess, so here we go again…

    1- If you want to separate parameters in 3 tokens: “/s”, “v1.1” and “1,3,4,5”, I already show how to do that via %%a, %%b and %%c replaceable parameters.

    2- If you want to separate parameters in 6 tokens: “/s”, “v1.1” “1”, “3”, “4” and “5” and have access to all of them at same time, you may use %1..%6 Batch parameters.

    3- If you want to separate parameters in any number of tokens (6 in this case) and process they one by one, use this code:

    :nextParam
       if "%1" equ "" goto endParams
       echo %1
       shift
       goto nextParam
    :endParams
    

    4- If you want to first separate parameters in 3 tokens: “/s”, “v1.1” and “1,3,4,5”, and then further separate the third token (%%c) in four parts, then I can not fathom out what the purpose of this could be. However, for illustrative purposes only, this is the way to do that:

    for /f "tokens=1-3" %%a in ("%*") do (
       echo First is %%a, Second is %%b, Third is %%c
       for %%d in (%%c) do echo %%d
    )
    

    5- If you want to store the 3 parameters in 3 variables, and eliminate commas in the third one, use this:

    for /f "tokens=1-3" %%a in ("%*") do (
       set First=%%a
       set Second=%%b
       set Third=%%c
    )
    set Third=%Third:,= %
    

    I strongly suggest you to read the description of the Batch commands you use (via HELP command) and do not use anything you don’t understand. Note that copy a code you don’t understand, modify it and then ask “why my code does not work?” is a nonsense. It is better to ask specific questions about specific doubts you may have.

    If no one of the 5 points above is what you want, then we can not further help you if you don’t explain us what you want (with words, NOT via code examples)…

    Antonio

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.