Hema Joshi
Hema Joshi

Reputation: 247

batch files command line arguments

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

Upvotes: 1

Views: 1304

Answers (2)

Alex K.
Alex K.

Reputation: 175936

In the 2nd bat file;

@echo whole command line is %*

Upvotes: 3

chalup
chalup

Reputation: 8516

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

Upvotes: 1

Related Questions