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 8429295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:17:46+00:00 2026-06-10T05:17:46+00:00

In my batch file I have the following variables: set collection=collection1 set environment=oracleDev set

  • 0

In my batch file I have the following variables:

set collection=collection1
set environment=oracleDev
set processChain1=-help,-startimport %environment% %collection% 

As you can see, my process chain contains two strings that are separated with a “,”.

Now I want to count the two strings (later it could be more then one string). I tried it with:

Set count=0
For %%j in (%%processChain1%%) Do Set /A count+=1
echo %count%

But there is the first mistake. It prints out 1 and not 2. Why?

After counting the strings I want to start an application with each parameter (string from the variable processChain1)
I try it with:

FOR /L %%G IN (1,1,%count%) DO (
     FOR /F "tokens=%count% delims=," %%H IN ("%processChain1%") DO java -jar App.jar %%H
)

This cant work correct now because the counter is wrong because of the first mistake. But I think if I can solve the first problem, the second should work fine. Is this correct?

  • 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-10T05:17:47+00:00Added an answer on June 10, 2026 at 5:17 am

    As far I can tell, right now, is counting 1 because there’s only one string in that var, you are making the split later, but your token count is already set to 1….

    You need to split the first string (delims=,) and then in the second part, work with each result.

    EDITED:

    Try this…

    @echo off
    set collection=collection1
    set environment=oracleDev
    set processChain1="-help" "-startimport %environment% %collection%"
    
    Set count=0
    For %%j in (%processChain1%) Do Set /A count+=1
    echo.Total count: %count%
    pause
    

    As you can see, I change the var processChain1 structure to separate the values with a space (default delimeter) and put every var in quotes…
    At least it works, and gives you the total count.

    Only of course, If you can use it in this way.

    Hope it helps.
    Cheers.

    If not.. take a look here, maybe it’s help : separate tokens in batch file

    Good luck


    EDITED 2 (to match new information)

    Batch file: Metalhead89.bat

    @echo off
    :: define the vars
    set collection=collection1
    set environment=oracleDev
    :: concatenate the vars with ++
    set processChain1=-help -startimport++%environment%++%collection%
    
    :: Get the total count plus, run each token found
    Set count=0
    For %%j in (%processChain1%) do (
        Set /A count+=1
        set line=%%j
        call :processToken
    )
    :: This will be printed out, at the end of the loop
    echo Total token count: %count%
    goto :eof
    
    :processToken
    for /f %%f in ("%line%") do (
    :: set the command var with your exe file for each token found
        set command=Running command: java -jar app.jar %%f
        call :runTheCommand
    )
    goto :eof
    
    :runTheCommand
    :: now we replace the doble ++ in the var string with space, to treat them as options
        set str=%command%
        set str=%str:++= %
    :: finally we do a echo of the command with the option included
        echo %str%
    goto :eof
    

    Now, Call that file from command line and you will get:

    Z:\>call Metalhead89.bat
    Running command: java -jar app.jar -help
    Running command: java -jar app.jar -startimport oracleDev collection1
    Total token count: 2
    

    Good luck buddy 😉

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

Sidebar

Related Questions

I have a following batch file echo Setting visual studio 2010 environment variables set
I have the following code in my batch file @ECHO OFF SET /P NAME=Enter
I have following batch file code: @echo off SET INSTALL_PATH=c:\program files\ :ask_again if exist
I have the following batch file: set var1=LongOption1 set var2=Longoption2 set var3=LongOption3 if %1
I have the following For loop in a batch file: for /R c:\test\src %%i
I have a batch file with the following code: for /f tokens=* %%a in
Reference Iterating arrays in a batch file I have the following: for /f "tokens=1"
i have the following batch file, which terminates the iTunes program so, that if
I have the following code in a batch file that is called by a
I have the following values in a DOS batch file (for example...): ..\Apple\Jones ..\Banana\Smith

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.