1.

Solve : How to determine what parameter passed to a batch and do something base on it.?

Answer»

Hello All,
I have one batch script that calls several other batch scripts. This batch received a parameter and pass it on to all the other batches by replacing %1 with that parameter.

How do I determine if %1==avalue and base on that value execute a section of my batch scripts?

Your help is appreciated. Thanks in advance.
you can try to echo the %1 value out to a file before it processes the next fileerobby,
I tested that interactively VIA the command line, it didn't work.
1) set %1=parameter that will be passed
2) echo %1 or %%1 or %%1% , see the result below:
Code: [Select]C:\Documents and Settings\>set %1=parmtopass

C:\Documents and Settings\>echo %1
%1

C:\Documents and Settings\>echo %%1
%%1

C:\Documents and Settings\>echo %%1%
%%1%It needs to be in the batch file you have on no OUTPUT yet. all you did with that statement was set the first var equal to parameter.

Post a snipet from the file so that I can SHOW you what I meanQuote from: LookingForHelp on July 23, 2008, 08:22:07 PM

erobby,
I tested that interactively via the command line, it didn't work.
1) set %1=parameter that will be passed
2) echo %1 or %%1 or %%1% , see the result below:
Code: [Select]C:\Documents and Settings\>set %1=parmtopass

C:\Documents and Settings\>echo %1
%1

C:\Documents and Settings\>echo %%1
%%1

C:\Documents and Settings\>echo %%1%
%%1%

lookingforhelp, it is CLEAR you do not yet understand about batch parameters. You cannot "test them interactively from the command line".

%1, %2, %3, etc are special variables that a batch file can use while it is running. They can't be set by the user as you tried to do.

Consider the following batch file which we will call param.bat.

Code: [Select]@echo off
echo parameter 1=%1
if "%1"=="cat" echo a %1 says Meow!
if "%1"=="dog" echo a %1 says Grrrrr!
if "%1"=="" echo no parameter passed

Save it into a folder as param.bat

Now open up a command window in that folder.

at the prompt type :

Code: [Select]param cat
then type

Code: [Select]param dog
then type

Code: [Select]param
Now do you see?

Dias,
Thanks I had already figured that out with erobby response.

Anyway. In case you didn't realized it, the tone of your reply was rude and disrespectful. While we would appreciate you responding to our post, I don't believe you're obligated to answer anyone post if you don't feel like it. I believe many people here are asking questions because they don't know or not sure how it should work.

Next time you decide to response to a post keep this in mind, try to show some respect to your fellow forum members. I am sure what you know can be learned by anyone. The fact that we don't know/understand it yet, doesn't mean we are idiot.


quote author=Dias DE verano link=topic=62085.msg394315#msg394315 date=1216883718]
Quote from: LookingForHelp on July 23, 2008, 08:22:07 PM
erobby,
I tested that interactively via the command line, it didn't work.
1) set %1=parameter that will be passed
2) echo %1 or %%1 or %%1% , see the result below:
Code: [Select]C:\Documents and Settings\>set %1=parmtopass

C:\Documents and Settings\>echo %1
%1

C:\Documents and Settings\>echo %%1
%%1

C:\Documents and Settings\>echo %%1%
%%1%

lookingforhelp, it is clear you do not yet understand about batch parameters. You cannot "test them interactively from the command line".

%1, %2, %3, etc are special variables that a batch file can use while it is running. They can't be set by the user as you tried to do.

Consider the following batch file which we will call param.bat.

Code: [Select]@echo off
echo parameter 1=%1
if "%1"=="cat" echo a %1 says Meow!
if "%1"=="dog" echo a %1 says Grrrrr!
if "%1"=="" echo no parameter passed

Save it into a folder as param.bat

Now open up a command window in that folder.

at the prompt type :

Code: [Select]param cat
then type

Code: [Select]param dog
then type

Code: [Select]param
Now do you see?


[/quote]Lookingforhelp, you are the rude and disrespectful one! I think you should modify your attitude. My post was clear and helpful. Having read your post, I think your English is maybe not good enough to understand that I was not being rude.


Discussion

No Comment Found