REM Get this parm into a variable
set Parm=%1
REM Is it a switch (starts with a -)
if "!Parm:~0,1!" EQU "-" (
REM If switch, then save the next parm in a Switch- variable
set Switch!Parm!=%2
shift
) else (
REM Not a switch, save in next Parm- variable
set /A Index+=1
set Parm-!Index!=%1
)
shift
goto :DoParms

Who is Participating?

Yes, it seems so. If you could pass quotes around the parm it could work, but of course Program2 may not like the quotes.

In your last question, you can't reset the %5 variable, as it is not a variable per se, but a value set by the command shell indicative of what it received/parsed. If you wanted to pass the _modified_ version of %5, you could change the batch to parse & concatenate, eliminating the "()" in %5 before you concat that parameter back.

How about passing CHAR(40) and then CHAR(41) for your right/left parens respectively in either VBSCript or in KIXtart?

HTH,

Kent

0

HCSHAWAuthor Commented: 2013-01-07

Thanks Kent, but the calling program does not allow me to modify the switches. If the data it is working with has the ( ) then that is what is being passed along. If it is any help, when that program builds p5 it is seeing the following.

Report#64869709
Customer_Ranking_by_MARGIN_(Monthly)_dog

It concatenates it to
Report#64869709(Customer_Ranking_by_MARGIN_(Monthly)_dog)
so it is adding in an extra set of ( ).

The way I solved this kind of problem was I wrote a little exe that does nothing more than pass its parameters to the cmd but placing quotes around the parameters based on their contents.
I configured the program to use this exe instead of the .cmd
If you have a C++ compiler I can give you my existing code. Otherwise I could try to convert it to .Net for you.

0

HCSHAWAuthor Commented: 2013-01-07

Kent, I see what you are saying, but I am limited in that I cannot modify program A or its output.

Beartlaoi, You have triggered a thought. Maybe what I really need to do is add a piece of code to strip the ( ) out of parm 5 BEFORE running it through the routine. I could substitute them with underscores. Do you have an easy way to do this using dos?

bmarone,
Thanks for the code example. In looking over it it appears to change the variable names to NAME1, NAME2, etc. The way the program currently works is it creates a variable name using the - (dash) value.

For Instance take the -tf 1sys010464886158-to.txt.

The program creates the following [Variable name Switch-tf and the value is 1sys010465368900-to.txt]
Switch-tf=1sys010465368900-to.txt

Your example code could possibly be modified to accommodate this, but I was hoping to avoid rewriting the code.

Just following suit. Then it sounds like probably not a need for the Index variable. Did you mean you don't want to rewrite the CMD file code, or changing the CMD file is OK, just not change PROGRAM1.EXE and PROGRAM2.EXE. Are you looking for this output:
Switch-tf=1sys010464886158-to.txt
Switch-s=Report#64869709(Customer_Ranking_by_MARGIN_(Monthly)_dog)
Switch-attach=E:\NxT\rd\tmp\mail7404.pdf
... and do you need a variable set for the first parameter (1sys010464886158.txt)?

I am experimenting with Beartlaoi solution to strip the ( ) out of P5. It looks like this might work for this solution.

Beartlaoi,
Your code has been translated as follows for this program. I just want to reassign %5 to the value that is created in TEMPP5. Forgive me for being lame, but the life of me, I can't get the %5 to get assigned. I know it is some simple syntax. Can you see what the issue is . As you might notice, I don't do this often enough to know all the gotchas of Dos.

Rem Clean up P5 of any ( )
set TempP5=%5
set TEMPP5=%TEMPP5:(=_%
set TEMPP5=%TEMPP5:)=_%set %5=%TEMPP5%

0

HCSHAWAuthor Commented: 2013-01-07

bmarone
From your approach, it looks like you are trying to eliminate the issue with the ( ) by changing the IF around. Do you feel that he ( ) in P5 are getting interpreted as part of the command string by the parser? Just a curiosity question.

You cant re-assign %5 since it is a passed-in parameter.
If you have First.cmd that calls the calling program that then calls blatcapture.cmd then the First.cmd should just pass %TEMPP5% instead of %5 to the program.

0

HCSHAWAuthor Commented: 2013-01-07

That's what I was suspecting. I was just hoping there was a little magic trick to make it work. I will give that a try.

0

HCSHAWAuthor Commented: 2013-01-07

Okay guys, both of these are excellent points. Thanks for commenting. My deli-ma is that the code I was trying not to modify is taking the command parms %1..%9 in order.

That means that if I use the clean up technique before the loop, the loop will still be processing %5 not the cleaned up %tempp5%. Ahggggg. This leans me toward what it seems both of you have concluded. I will need to interject a program to strip the ( ) in the incoming parms, and then pass along to blatcapture.

bmarone, your code example seems to be a straightforward example of how to code for this cleanup program. thx.

Thank you all for your prompt and informative responses.

0

HCSHAWAuthor Commented: 2013-01-07

Thanks again for the hearty dialogue.

0

HCSHAWAuthor Commented: 2013-01-08

Just a recap for those who came here to find an answer to your ( ) problem.

First ( ) in a Parm that was processed by the IF ELSE was causing the code to fail. For some reason it was recognizing the ( ) in the Parm as part of the code and was aborting the routine. I coded a stripper (see bmarone's comments above) to remove the ( ) and this worked but wasn't a clear coding solution. I also wanted to leave the ( ) in the Parm if possible since stripping them out made the text less readable.

Second, If statements in DOS are a BEAR. To do a proper IF ELSE that includes more than 1 command you have to use ( ) in a precise format.
IF test do (
truelogic
) else (
falselogic
)
If you are going to use the ELSE it must be )spaceELSEspace(. Now there is a lot of dialogue about using the ELSE which you will find when you do your research. It can be tricky to get the desired result. My recommendation is to not use the ELSE and write your code with GOTO's. (bmarone's suggested that approach as well). That said, that is what I ended up doing to clean up the issues I was having. This code will now accept a parm with ( ) without failing.

Here is how the code was re-written
REM Init index for non switch parms
set Index=0

REM ------------------------
REM Loop until no more parms found
REM ------------------------