开发者

how to pass a complex chain as an argument to a batch 'index1','index2','index3'

I want to pass this string 'index1','index2','index3' to a batch

test2.cmd 1 'index1','index2','index3' 3

and if test2.cmd is

echo %1
echo %2
echo %3

I'd lik开发者_如何学Ce to see

echo 1
echo 'index1','index2','index3'
echo 3

But it does not work... cause I see

echo 1
echo'index1'
echo 'index2'

How can I fix this please?


Just enclose the string in double quotes:

test2.cmd 1 "'index1','index2','index3'" 3

Edit to answer your comment:

Also change test2.cmd to

echo %1
echo %~2
echo %3


The problem is here that "," is a delim for parameters, so you have to replace it, or quote the complete parameter like Vicky advised.

You got more problems if index1,index2,.. can contain quotes, then the parameter will be broken.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜