tags:

views:

227

answers:

2

I have a batch file (BAT1.bat) which returns the following string:

"Login credential: 7o5g4cika"

I need to send a part of the result (ie "7o5g4cika") as argument to another bat file BAT2.bat.

BAT2.bat 7o5g4cika

How can I combine these to a single bat file?

+2  A: 

This line will do what you want:

for /F "tokens=3" %v in ('BAT1.bat') do call BAT2.bat %v

What this line does is call BAT1.bat, then parses its output using the options specified after the /F. Specifically, "tokens=3" tells the shell to take the third token and put it in the variable. Then, BAT2.bat is called with the variable as its parameter.

Assuming you are going to use this in a batch file, you're going to want to double the percent signs:

for /F "tokens=3" %%v in ('BAT1.bat') do call BAT2.bat %%v

For more details, type

for /?

from the command line

itsadok
Come on, no upvotes?
itsadok
There, now you have one :-)
Joey
A: 

Make a call like Bat1.bat | Bat2.bat then put some code at the beginning of bat2.bat to get the right substring.

If you can't touch bat2.bat, create a bat3.bat, dedicated to tweak "Login credential: 7o5g4cika" into "7o5g4cika" and make a call like: Bat1.bat | Bat3.bat | Bat2.bat

Vinzz
You want to append the text to another batch file?
Joey