Passing Parameters from external process

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
markymark
Posts: 2
Joined: 12 Aug 2010 02:41

Passing Parameters from external process

#1 Post by markymark » 12 Aug 2010 02:56

Hi

I wonder whether anyone can give me some pointers on the following scenario. I have an external process which captures a UK postcode as a variable, and I want to pass that into a bat file as a variable. The UK postcode format is of the format A1 1AA, and that is the variable (sPostcode) captured in the external process.

When I pass "C:\Application\mi_process.bat " + sPostcode

and in the bat file use
echo %1

I am returned with just the first portion of the postcode - i.e. A1

I have tried "C:\Application\mi_process.bat " + chr$(34) + sPostcode + chr$(34)

And the echo %1 returns
"A1 1AA"

which appears to be nearly there, but I don't want the variable to store the quotes.

I can use %* in the original and it returns the full postcode but want to be able to keep postcodes referenced by separate %n variables so that I can extend functionality to include passing numerous postcodes.

So I guess the more simplistic question is where I am passing a variable like this:
c:\application\mi_process.bat 1 2
what do I need to do to read 1 2 as a single variable (i.e. %1)

Any ideas?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Passing Parameters from external process

#2 Post by aGerman » 12 Aug 2010 04:07

Pass it enclosed in quotes. Use %~1 to remove enclosing quotes into your batch code.

Otherwise it comes as two parameters. You could also handle this as follows
set "postcode=%1 %2"

Regards
aGerman

markymark
Posts: 2
Joined: 12 Aug 2010 02:41

Re: Passing Parameters from external process

#3 Post by markymark » 12 Aug 2010 04:30

Hi

thanks for that aGerman. The %~1 works as required.

8)

Thanks again

Post Reply