Reputation: 29
I have batch1 (the parent batch) which calls batch2, 3, etc. Batch2 does some stuff, sets a variable (%fullname%) and exits. Batch 3 is supposed to use the variable from batch2.
Batch1
Call Batch2
echo %fullname%
Call Batch3
I've tried
Call Batch 3 %fullname%
Call Batch3 %1
etc
The echo %fullname% is successful in Batch1. The %fullname% is not getting into Batch3. I hope this is something simple that I'm missing because I'm tired of looking at this batch file. Plus, I have a lot of variables and calls, more than this example shows.
Should I ditch the parent batch and have the child batches call each other? Simpler? e.g. Batch1 calls Batch2, batch2 calls batch3, batch3 calls batch4 etc.
I've googled this. The question is apparently too simple to have been asked before.
Upvotes: 0
Views: 1683
Reputation: 434
batchone.bat:
@echo off
call batchtwo.bat
call batchthree.bat
pause
exit
save as batchone.bat
batchtwo.bat:
@echo off
::insert code here
set fullname=mechengr02
exit /b
save as batchtwo.bat
batchthree.bat:
@echo off
echo hello %fullname%
exit /b
save as batchthree.bat
note that these are three different batch files. i just tested it.
hope that helped!
Upvotes: 1