Environmental variables and command prompt

Features wanted...
spamalam
Posts: 20
Joined: 23 Jun 2007 22:10

Environmental variables and command prompt

Post by spamalam »

I don't know if this is a bug or on purpose.

I often need to work with environmental variables, changing them and then doing a build. I refer variables to other variables:
ie.
JAVA_HOME=%JAVA_HOME15%
JAVA_HOME14=c:\java\1.4.2_10
JAVA_HOME15=c:\java\1.5.0_06

PATH=%JAVA_HOME%\bin;etc.

Due to how these are interpretted, i can't type:
set JAVA_HOME=%JAVA_HOME14%
as the path has already been evaluated.

Anyway, I've found that if i launch a command prompt from XY, it does not pick up changes I've made to the environmental variables since launch but instead keeps the variables I'd set when XY was first launched.

I was wondering:
a) can the command prompts be changed to always pick up the latest environmental variables; as if it were being launched with cmd and then cd'd to the directory?
b) can all the command prompt shortcuts be the same shortcut settings? I like to have my command prompts fill the screen (so i set a common size setting and tell it to apply to all)... unfortunately when launching from XY each new location resets the size as if it were a new shortcut.

I'm not running the latest beta atm, but i think both of these will still be the case.

admin
Site Admin
Posts: 65050
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Environmental variables and command prompt

Post by admin »

spamalam wrote:a) can the command prompts be changed to always pick up the latest environmental variables; as if it were being launched with cmd and then cd'd to the directory?
b) can all the command prompt shortcuts be the same shortcut settings? I like to have my command prompts fill the screen (so i set a common size setting and tell it to apply to all)... unfortunately when launching from XY each new location resets the size as if it were a new shortcut.
a) No. ENV vars are read once at first usage and then cached.
b) I don't understand the question.

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Environmental variables and command prompt

Post by j_c_hallgren »

admin wrote:b) I don't understand the question.
:roll: I think I just figured it out after reading it about 5 times! It seems to refer to the "Open Command Prompt here" function and the DOS window size that is thus created...user wants to have all these windows be a particular size, I suspect.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

mwb1100
Posts: 213
Joined: 19 May 2007 06:20

Post by mwb1100 »

I think that the user wants the env variable settings for a new command window read from the registry at the time the command window is opened. This way you can use the Computer Properties dialog to change the environment settings and get a new window with those settings. This seems to be the way that Explorer works.

Edit: Umm looks like I should read a little more carefully - I'm talking about a), which Don has already addressed, but still I think that this is the behavior that should probably apply to whenever a program is launched - not just a command window.

spamalam
Posts: 20
Joined: 23 Jun 2007 22:10

Post by spamalam »

@a, well that's a bugger then :( How does it work in explorer? Using the "command prompt from here" plugin (windows powertool), if i change my varaibles and launch a cmd session through explorer it uses the new variables not the ones from explorer launch. This is the behaviour that would be highly beneficial.

@b), As an example:

I load up a command prompt from c:\fluffy, and then change the properties to make it fullscreen and change the colour to green (or something), then load up a command prompt from c:\fluffy\pillow all of my changes for the cmd.exe that's just been launched are back to default.

I'm guessing its because the title of the cmd window has changed?

I guess its not a big deal if a can not be addressed, since it largely invalidates the usage of "command prompt from here" for me if i can't have it pick up the latest varibles :(

oh well :(

lukescammell
Posts: 744
Joined: 28 Jul 2006 13:15
Location: Kent, UK
Contact:

Post by lukescammell »

IMO, for cmd line monkeys these are two very good suggestions. I've known a couple of Java devs who do this kind of thing the whole time (for testing between JRE versions).

Does it really take all that long to read the ENVs before a cmd line is opened up each time? It seems a bit silly for a cmd line in a power-user tool to be out of date with the rest of the system seeing as how a cmd line is only going to be used by power users.
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

admin
Site Admin
Posts: 65050
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Post by admin »

lukescammell wrote:IMO, for cmd line monkeys these are two very good suggestions. I've known a couple of Java devs who do this kind of thing the whole time (for testing between JRE versions).

Does it really take all that long to read the ENVs before a cmd line is opened up each time? It seems a bit silly for a cmd line in a power-user tool to be out of date with the rest of the system seeing as how a cmd line is only going to be used by power users.
It takes not that long but long enough to warrant caching.

What I could do is:
(a) a menu command to explicitly Refresh ENVs Cache
(b) a tweak to always refresh it before using an ENV
(c) well, if it's just before a cmd line is opened... I could do that! Any objections anybody?

spamalam
Posts: 20
Joined: 23 Jun 2007 22:10

Post by spamalam »

One of the options would be nice.

Of course i could create bat files that switch the env environments and stick them all over the place, which I have done in the past, however this would disrupt / negate the right click and command prompt from here within XY and also be very annoying to maintain when ctrl+break is much easier for updating ENV settings. They are also referential, so JAVA_HOME can be set to JAVA_HOME15 which is placed on the path. Some way for XY to refresh those env values and pass them onto the cmd would be very welcomed.

Any options for feature b? :)

admin
Site Admin
Posts: 65050
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Post by admin »

spamalam wrote:One of the options would be nice.

Of course i could create bat files that switch the env environments and stick them all over the place, which I have done in the past, however this would disrupt / negate the right click and command prompt from here within XY and also be very annoying to maintain when ctrl+break is much easier for updating ENV settings. They are also referential, so JAVA_HOME can be set to JAVA_HOME15 which is placed on the path. Some way for XY to refresh those env values and pass them onto the cmd would be very welcomed.

Any options for feature b? :)
But b) would slow down all operations using ENV variables (scripting, UDCs...) a bit. Any other opinions out there? The tweak would be DoNotCacheEnv = 1 or so...

spamalam
Posts: 20
Joined: 23 Jun 2007 22:10

Post by spamalam »

What about a big button with refresh ENV variables? :lol: Would at least avoid having to restart XY to refresh and won't hit scripting.

admin
Site Admin
Posts: 65050
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Post by admin »

spamalam wrote:What about a big button with refresh ENV variables? :lol: Would at least avoid having to restart XY to refresh and won't hit scripting.
Menu View | Caches | Refresh ENV Cache would be the natural place...

spamalam
Posts: 20
Joined: 23 Jun 2007 22:10

Post by spamalam »

admin wrote:
spamalam wrote:What about a big button with refresh ENV variables? :lol: Would at least avoid having to restart XY to refresh and won't hit scripting.
Menu View | Caches | Refresh ENV Cache would be the natural place...
That would be cool :D

pmoore
Posts: 28
Joined: 27 May 2008 13:50

Post by pmoore »

admin wrote:
spamalam wrote:What about a big button with refresh ENV variables? :lol: Would at least avoid having to restart XY to refresh and won't hit scripting.
Menu View | Caches | Refresh ENV Cache would be the natural place...
I think there's a Windows message that gets sent when the env changes. You could trap that and update the environment cache automatically.

(Checks SDK) Yes, WM_SETTINGCHANGE.
To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message. This allows applications, such as the shell, to pick up your updates.
Paul.

admin
Site Admin
Posts: 65050
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Post by admin »

pmoore wrote:
admin wrote:
spamalam wrote:What about a big button with refresh ENV variables? :lol: Would at least avoid having to restart XY to refresh and won't hit scripting.
Menu View | Caches | Refresh ENV Cache would be the natural place...
I think there's a Windows message that gets sent when the env changes. You could trap that and update the environment cache automatically.

(Checks SDK) Yes, WM_SETTINGCHANGE.
To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message. This allows applications, such as the shell, to pick up your updates.
Paul.
Ah, thanks. Make a note...

spamalam
Posts: 20
Joined: 23 Jun 2007 22:10

Post by spamalam »

Great find pmoore!

Post Reply