A request for a new feature for the "set" command...

Not open for further replies.
May 24, 2010
Northlake, Il
I use "SetLocal/EndLocal" a lot to avoid "polluting" the environment - and these can often be nested somewhat deeply as batch files call other batch files. However, there are times when I want to set a variable in an upper environment, or even the root environment (i. e. that of the TCMD/TCC session in which I am running the batch file), and the only way I've found to do this is the (fairly long and complicated) code sequence:

REM Where I am setting the variable:
Set Variable=...
REM Set variable as a volatile variable in the registry
Set /V Variable=%Variable

REM Where I am retrieving the variable's value:
REM Retrieve variable from registry
REM (Is this the only way????)
Set Variable=%@ExecStr[Set /V Variable]
DoWhatever with %Variable as needed...
REM Drop variable from the registry (assuming this even works)
Set /V Variable=


"/U#": Set in the environment # levels up from the current environment (may not be generally useful...)

"/U": Set in the environment one level up. (Specifying without a count - one level up - may be generally useful...)

"/T" or "/R": Set in the "Top" or "Root" environment...

I know I can avoid using SetLocal/EndLocal commands and drop the batch-file variables I no longer need at the bottom of the batch file, but doing this for all no-longer-needed variables that were used and avoiding variable conflicts with the "current" envirionment is more effort/discipline than I really want to put into this. (If setting a variable in a "lower" environment that was defined in an "upper" environment didn't "re-create" the variable in the "lower" environment (again, like other languages that have variable scoping) would do the job, but I know that this would probably "break" too much existing code and is therefore too much to ask.)

I do this regularly in C Plus Plus programs (and I am refering to environment variables) so I absolutely know it can be done...
May 20, 2008
Syracuse, NY, USA
On Tue, 02 Nov 2010 19:32:52 -0400, mathewsdw <> wrote:

|Set /V Variable=%Variable
|REM Where I am *retrieving* the variable's value:
|REM Retrieve variable from registry
|REM (Is this the only way????)
|Set Variable=%@ExecStr[Set /V Variable]

My 4UTILS plugin offers:

v:\> help @GEV
@GEV[name[,s|u|v|d]] = value of [registry] environment variable


v:\> set /v foo=bar

v:\> echo %@gev[foo,v]

|/U# - Set in the environment # levels up from the current environment (may not be generally useful...)
|/U - Set in the environment one level up. (Specifying without a *count* - one level up - may be generally useful...)

What's a "level"?

The only hierarchy of environments is the parental one ... processes inherit the
environment of their parent. And that hierarchy is not generally available to a
process or to the programmer.

My SYSUTILS plugin offers EXPORT and @PSET[] which may be helpful.

v:\> help export
EXPORT var [var [...]] (to parent 4NT/TCC)

v:\> help @pset

get[unset[set]] variable in process <pid>

returns value (get/set) or var (unset) on success, else an empty string
May 20, 2008
Syracuse, NY, USA
On Tue, 02 Nov 2010 22:51:05 -0400, Charles Dye <> wrote:

|---Quote (Originally by vefatica)---
|What's a "level"?
|---End Quote---
|SETLOCAL nesting level, I think.

OK, I see. The comments I made about EXPORT and @PSET are unrelated to
May 24, 2010
Northlake, Il
You can already do this by exporting variables in the ENDLOCAL command.

Stated simpy, Rex, thank you very much. I will note that I've been using your product(s) for many years (starting with Windows 3.1, I think), and while I read the "help" file fairly thoroghly years ago, since my eyesight has largely failed me (as I know I've mentioned in the past, I have to use the screen magnfier app and/or a large font to even use a computer) I'm reading things pretty much on an "as needed" basis and this functionality of the "EndLocal" command I was completely unaware of, and it never occurred to me that the "EndLocal" command might have those "features". Again, thanks very much Rex! The more I find out about this product, the better it is!!!!
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M TCMD/TCC Feature Request... Support 4
dcantor Feature request for SENDMAIL Support 0
Jay Sage Request Re Aliases CD_LEAVE and CD_ENTER Support 2
B Request Manual Key fails Support 3
rconn News Take Command v22 Request for Features Support 0
vefatica HELP request Support 4
dcantor Request for XenForo Support 2
S Fixed BDEBUGGER died on invalid watch request Support 4
M A somewhat humorous minor-request related to "Shift" command... Support 4
M How to do now or maybe a request for new functionality Support 3
M time /s - enhancement request Support 5
rconn Do NOT request return receipt! Support 7
Dick Johnson cdd - is this a bug or a feature? Support 7
rconn News Take Command v21 Feature Requests Support 3
vefatica OT: Is this a Windows feature? Support 6
S Documentation KEYSTACK - has this feature been dropped? Support 5
rconn News New "Previous thread / Next Thread" feature Support 0
S Debug feature bug? Support 17
R TC 13 / you forgot to list a new feature Support 2
rconn Last call for v12 feature requests Support 59
rconn Call for v11 feature requests Support 35
P if and text: bug or feature? Support 2
V Set path permanently from within TCC? Support 3
S Debugger keeps breaking with no break point set. Support 1
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R How to? Set default application in a special folder Support 4
A How to? Set up SMTP password in TCC-RT Support 1
vefatica WAD More SET /A woes Support 4
vefatica SET /A and multidimensional array. Support 1
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D Need to set Take Command font size when switching to high DPI display Support 0
P "Set" command behavior - a bug? Support 3
M How to? Set the ribbon titles to mixed case Support 1
X How to set %_INIREAD result to variable Support 5
M WAD Set statements in () causes problems Support 8
M How to? How to set a default TITLE for newly opened tab? Support 2
M Fixed Set "VAR=VAL" format causes problems Support 12
vefatica SET /A var=expression=digits Support 3
cxxl Set encoding for batch file Support 4
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
vefatica SET /A var\=...? Support 10
dcantor Documentation SET /T: missing from heading Support 0
fpefpe Documentation Set /v Support 4
vefatica What's SET /Z? Support 1
R Fixed set /r has stopped working in build 35 Support 4
BeechComer Debugger: how to set %1 variable? Support 3
fpefpe How to? Global variable set /v Support 4
fpefpe Documentation Can the title line of tcmd be set? Support 4
J How to set working directory Support 10
Jay Sage Failure of ACTIVATE to Set a Window Position Support 3

Similar threads