[TC 9.20] Empty environment variables are broken
Moderators: white, Hacker, petermad, Stefan2
[TC 9.20] Empty environment variables are broken
From here.
Empty environment variables are disabled or broken in TC 9.2.
Can't find any information and reason for disabling in changelog.
Hope it's a bug, and previous behavior will be restored. Hard to use TC in current state
Empty environment variables are disabled or broken in TC 9.2.
Can't find any information and reason for disabling in changelog.
Hope it's a bug, and previous behavior will be restored. Hard to use TC in current state
"I used to feel guilty in Cambridge that I spent all day playing games, while I was supposed to be doing mathematics. Then, when I discovered surreal numbers, I realized that playing games IS math." John Horton Conway
- ghisler(Author)
- Site Admin
- Posts: 48079
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: [TC 9.20] Empty environment variables are broken
TC doesn't distinguish between empty and non-existing environment variables, because you cannot set empty environment variables as a user, neither with cmd.exe nor via Control Panel - System:
In cmd.exe,
set test=
deletes the Environment variable.
In Control Panel, the OK button remains grayed out when you try to set a variable, but don't specify a value.
The % character is a perfectly valid character in a name.
So TC cannot know whether Results80%to100%.xls is the right name, or %to100% needs to be replaced.
In cmd.exe,
set test=
deletes the Environment variable.
In Control Panel, the OK button remains grayed out when you try to set a variable, but don't specify a value.
The % character is a perfectly valid character in a name.
So TC cannot know whether Results80%to100%.xls is the right name, or %to100% needs to be replaced.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: [TC 9.20] Empty environment variables are broken
Yes. Now TC doesn't distinguish.ghisler(Author) wrote: ↑2018-07-27, 08:03 UTC TC doesn't distinguish between empty and non-existing environment variables,
But TC 9.12 (and early versions) understand empty environment variables.
Empty environment variables can exist.ghisler(Author) wrote: ↑2018-07-27, 08:03 UTCyou cannot set empty environment variables as a user, neither with cmd.exe nor via Control Panel - System:
It's possible with third-party applications. Examples with Autorun plugin are here (I use a lot of such envvars in TC for years).
With Rapid Environment Editor possible to set empty "test" user variable, and it's displayed in Windows EnvVars list:
Image: https://i.imgur.com/esA8vfV.png
"I used to feel guilty in Cambridge that I spent all day playing games, while I was supposed to be doing mathematics. Then, when I discovered surreal numbers, I realized that playing games IS math." John Horton Conway
Re: [TC 9.20] Empty environment variables are broken
It's possible to fix such behavior with escape character.ghisler(Author) wrote: ↑2018-07-27, 08:03 UTCThe % character is a perfectly valid character in a name.
So TC cannot know whether Results80%to100%.xls is the right name, or %to100% needs to be replaced.
For example, in Autohotkey it works in such way.
We set empty "%test%".
For start Program.exe we use:
Code: Select all
Run, Program%test%.exe
Code: Select all
Run, Program`%test`%.exe
Or you can add "switch" key in wincmd.ini - "Allow empty environment variables like in TC 9.12 and earlier", please.
TC always care about compatibility.
Removing empty envvars is a great strike, because it works for years, and in TC 9.20 was suddenly disabled.
"I used to feel guilty in Cambridge that I spent all day playing games, while I was supposed to be doing mathematics. Then, when I discovered surreal numbers, I realized that playing games IS math." John Horton Conway
- ghisler(Author)
- Site Admin
- Posts: 48079
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: [TC 9.20] Empty environment variables are broken
I wasn't aware that it was different in TC 9.12. I can change it, but how do I set system-wide empty environment variables? Are they really occuring in the wild?Yes. Now TC doesn't distinguish.
But TC 9.12 (and early versions) understand empty environment variables.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: [TC 9.20] Empty environment variables are broken
ghisler(Author),
You can set system-wide empty variables with e.g. setx command:
However it seems that Windows can't process such variables correctly. Empty system variable (e.g. one that is set with setx) is visible in system properties dialog but is missing in set command output. GetEnvironmentStrings doesn't list such variable, GetEnvironmentVariable returns 0 with error code telling that variable is not found, ExpandEnvironmentStrings doesn't expand them (leaves %test1% unchanged, as if variable wouldn't exist).
But you can also set process-wide empty variable (what Autorun.wdx does) with SetEnvironmentVariable(L"test2", L"") call. Such variable is expanded by GetEnvironmentVariable (function returns 0 because variable is empty but GetLastError() indicates that there was no error), it is listed in GetEnvironmentVariable output, and it is also properly expanded by ExpandEnvironmentStrings to an empty string.
Such variables are quite useful in TC sometimes, e.g. for launching different software versions according to TC or Windows architecture. Such variables may be easilly set with Autorun.wdx plugin and then referenced in INI or buttonbars:
(this Autorun.cfg block will set OS_EMPTY_OR_64 variable to empty value in 32-bit Windows or to "64" in 64-bit Windows)
(this would launch program from SomeTool folder in 32-bit Windows or same program from SomeTool64 folder in 64-bit Windows, if TC could expand empty variables to empty strings)
(this would launch SomeOtherTool.exe program in 32-bit Windows or SomeOtherTool64.exe in 64-bit Windows, if TC could expand empty variables to empty strings)
You can set system-wide empty variables with e.g. setx command:
Code: Select all
setx test1 ""
But you can also set process-wide empty variable (what Autorun.wdx does) with SetEnvironmentVariable(L"test2", L"") call. Such variable is expanded by GetEnvironmentVariable (function returns 0 because variable is empty but GetLastError() indicates that there was no error), it is listed in GetEnvironmentVariable output, and it is also properly expanded by ExpandEnvironmentStrings to an empty string.
Such variables are quite useful in TC sometimes, e.g. for launching different software versions according to TC or Windows architecture. Such variables may be easilly set with Autorun.wdx plugin and then referenced in INI or buttonbars:
Code: Select all
If %SYSINFO_OSARCH% = 32 Then
SetEnv OS_EMPTY_OR_64
SetEnv OS_EMPTY_OR_64_SLASH
Else
SetEnv OS_EMPTY_OR_64 64
SetEnv OS_EMPTY_OR_SLASH_64 \64
EndIf
Code: Select all
Program: %COMMANDER_PATH%\Tools\SomeTool%OS_EMPTY_OR_64%\SomeTool.exe
Parameters: ...
Code: Select all
Program: %COMMANDER_PATH%\Tools\SomeOtherTool\SomeOtherTool%OS_EMPTY_OR_64%.exe
Parameters: ...
- ghisler(Author)
- Site Admin
- Posts: 48079
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: [TC 9.20] Empty environment variables are broken
Yes, I have implemented the GetLastError() check now (for RC2) to distinguish between empty and non-existing environment variables.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- ghisler(Author)
- Site Admin
- Posts: 48079
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Re: [TC 9.20] Empty environment variables are broken
This should work now in RC2, please test it!
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Re: [TC 9.20] Empty environment variables are broken
Thank you very much, works like a charm!
Re: [TC 9.20] Empty environment variables are broken
Thank you
"I used to feel guilty in Cambridge that I spent all day playing games, while I was supposed to be doing mathematics. Then, when I discovered surreal numbers, I realized that playing games IS math." John Horton Conway