Passing the result of one batch file to another?

I have a batch file (BAT1.bat) that returns the following line:

"Input credentials: 7o5g4cika"

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

BAT2.bat 7o5g4cika

      

How can I combine them with one bat file?

+2


source to share


2 answers


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 parameters specified after /F

. Specifically, it "tokens=3"

tells the shell to take the third token and place it in a variable. Then it is called BAT2.bat

with a variable as a parameter .

Assuming you are going to use this in a batch file, you will need to double the percentage signs:



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

      

For more information enter

for /?

      

from the command line

+3


source


Make a type call Bat1.bat | Bat2.bat

, then enter the code at the beginning of bat2.bat to get the substring you want.



If you can't touch bat2.bat , create a bat3.bat dedicated to configuring the "Login: 7o5g4cika" credentials to "7o5g4cika" and call for example:Bat1.bat | Bat3.bat | Bat2.bat

-1


source







All Articles