views:

52

answers:

2

hi i am setting a string in a variable

set main=svn commit -m "Build version number update" install\msbuild\VersionNumber.txt

and passing "%main%" as a command line argument to another script template.bat .

but in template.bat "Build version number update" is cosidered a 2nd arg and rest as 3rd

one.

please tell me how to pass the variable main as a single argument.

thanks

A: 

Variable %main% contains spaces, so if you use it like this:

template.bat %main%

Batch will interpret it like this:

template.bat svn blah blah blah

So %1 will be only "svn", etc. If you want entire contents of %main% to be treated as a single argument, you have to put quotes around it:

template.bat "%main%"

The problem is, the %1 now contains those quotes. You have to remove them inside template.bat using tilde:

%~1
chalup
+3  A: 

In the 2nd bat file;

@echo whole command line is %*
Alex K.
Nice one, didn't thought about %*. It won't work however, if more arguments are passed to template.bat.
chalup