Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.



Windows 7: Batch Scripting: How to mix SETLOCAL with non-local?

07 Nov 2012   #1

Windows 7
 
 
Batch Scripting: How to mix SETLOCAL with non-local?

I have a batch file, to be called like this:

call setvars

It's purpose is to setup a few environment variables:

:: This is setvars.cmd
set temp1=abc
set temp2=xyz
set MYVAR1=%temp1%4711%temp2%
set MYVAR2=%temp2%_%temp1%


This just illustrates the general idea. The user of setvars.cmd is supposed to be only interested in the variables MYVAR1 and MYVAR2, but he also sees the temporary variables temp1 and temp2.

Ideally, I would use setlocal to make temp1 and temp2 invisible to the outside, but this doesn't work here, because it also would hide MYVAR1 and MYVAR2.

As a workaround, I could use a temporary file:

setlocal
set temp1=abc
set temp2=xyz
echo set MYVAR1=%temp1%4711%temp2%>tempfile.bat
echo set MYVAR2=%temp2%_%temp1%>tempfile.bat
endlocal
call tempfile
del tempfile.bat

but this looks overly complicated to me. Is there a simpler solution to my problem?

My System SpecsSystem Spec
.

Reply

 Batch Scripting: How to mix SETLOCAL with non-local?





Thread Tools



Similar help and support threads for2: Batch Scripting: How to mix SETLOCAL with non-local?
Thread Forum
Solved How to run a batch file at logoff & some batch scripting help please Backup and Restore
Scripting host Customization
Need help with windows batch scripting to create game for blind child General Discussion
scripting General Discussion
Scripting? General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 07:12 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33