Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a windows batch file - called fileA.bat, which contains a variable set in it. Sample code of fileA.bat:

set fileA_username=michael

now i have another batch file, called fileB.bat, which needs to access this variable set in fileA.bat.

So the code that I write in fileB.bat would want to do something like this:

set fileB_username = %fileA_username%

and then keep using the fileB_username in the script code.

FileB would be calling fileA as part of execution like this:

code in fileB:

call fileA.bat
set fileB_username = fileA_username
if fileB_username

how do i access variables that are set in external batch files? Thanks.

share|improve this question

Unless you specify SETLOCAL or unset the variable explicitly in batch file A, the variable will be global and accessible to your second batch file.

For further information see Why unload variables in Windows batch files

share|improve this answer
thanks for the clarification. And the link you gave provided a very concise explanation into what I was looking for. Really appreciate your help. Thanks! – tsum Nov 28 '13 at 1:55

You've got a typo in the variable name: fielA_username vs. fileA_username, otherwise your code is good. Also you should avoid pretty spaces around = sign in SET command since they will become a part of variable name and its value (try: SET foo=bar && SET foo = bar && SET foo).

@REM this is setenv.bat


@REM and this is "main" script

CALL setenv.bat

@REM append something to the value

REM print the current value

share|improve this answer
Thanks for the tips, and neat explanation. I got the point now. Appreciate your help! – tsum Nov 28 '13 at 1:56
@tsum, you can vote and accept if you feel so ;) – Free Consulting Nov 28 '13 at 3:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.