Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Invoke a parameter in a batch file with comma-delimiter

Tags:

batch-file

I want to invoke a batch file with a comma-delimited paramater. How can I achieved this?

I want it like this example.

I have a text.bat with the script:

@echo off
set test=%1
echo Sample %test% batch.

I want to run the batch like this:

c:\text.bat this,is,sample

and I am expecting a result like this:

Sample this,is,sample batch.

Any idea how I could achieve this?

Thanks.

like image 912
quinekxi Avatar asked Nov 16 '11 02:11

quinekxi


1 Answers

Wow! I didn't know commas behaved that way.

You have two options.

You can use this script:

@echo off
set test=%~1
echo Sample %test% batch.

And run it with:

C:\text.bat "this,is,test"

The %~1 represents the first argument without quotes. The quotes group the comma-delimited list as a single argument.

Or

You can use this script:

@echo off
set test=%*
echo Sample %test% batch.

And run it with:

C:\text.bat this,is,test

The %* represents the command line arguments as they were typed.

like image 194
Hand-E-Food Avatar answered Oct 14 '22 01:10

Hand-E-Food