[TC 9.20] Empty environment variables are broken

Bug reports will be moved here when the described bug has been fixed

Moderators: Stefan2, white, sheep, Hacker

Post Reply
User avatar
LonerD
Senior Member
Senior Member
Posts: 292
Joined: 2010-06-19, 20:18 UTC
Location: Donetsk

[TC 9.20] Empty environment variables are broken

Post by *LonerD » 2018-07-26, 18:15 UTC

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 :(
Total Commander DreamLair - dream always, think totally, be the commander of you own life.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 36549
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 9.20] Empty environment variables are broken

Post by *ghisler(Author) » 2018-07-27, 08:03 UTC

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.
Author of Total Commander
http://www.ghisler.com

User avatar
LonerD
Senior Member
Senior Member
Posts: 292
Joined: 2010-06-19, 20:18 UTC
Location: Donetsk

Re: [TC 9.20] Empty environment variables are broken

Post by *LonerD » 2018-07-27, 11:42 UTC

ghisler(Author) wrote:
2018-07-27, 08:03 UTC
TC doesn't distinguish between empty and non-existing environment variables,
Yes. Now TC doesn't distinguish.
But TC 9.12 (and early versions) understand empty environment variables.
ghisler(Author) wrote:
2018-07-27, 08:03 UTC
you cannot set empty environment variables as a user, neither with cmd.exe nor via Control Panel - System:
Empty environment variables can exist.
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
Total Commander DreamLair - dream always, think totally, be the commander of you own life.

User avatar
LonerD
Senior Member
Senior Member
Posts: 292
Joined: 2010-06-19, 20:18 UTC
Location: Donetsk

Re: [TC 9.20] Empty environment variables are broken

Post by *LonerD » 2018-07-27, 12:02 UTC

ghisler(Author) wrote:
2018-07-27, 08:03 UTC
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.
It's possible to fix such behavior with escape character.
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
For start Program%test%.exe we use:

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.
Total Commander DreamLair - dream always, think totally, be the commander of you own life.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 36549
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 9.20] Empty environment variables are broken

Post by *ghisler(Author) » 2018-07-29, 07:12 UTC

Yes. Now TC doesn't distinguish.
But TC 9.12 (and early versions) understand empty environment variables.
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?
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8142
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [TC 9.20] Empty environment variables are broken

Post by *MVV » 2018-07-30, 04:47 UTC

ghisler(Author),
You can set system-wide empty variables with e.g. setx command:

Code: Select all

setx test1 ""
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:

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
(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)

Code: Select all

Program: %COMMANDER_PATH%\Tools\SomeTool%OS_EMPTY_OR_64%\SomeTool.exe
Parameters: ...
(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)

Code: Select all

Program: %COMMANDER_PATH%\Tools\SomeOtherTool\SomeOtherTool%OS_EMPTY_OR_64%.exe
Parameters: ...
(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)

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 36549
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 9.20] Empty environment variables are broken

Post by *ghisler(Author) » 2018-07-30, 09:48 UTC

Yes, I have implemented the GetLastError() check now (for RC2) to distinguish between empty and non-existing environment variables.
Author of Total Commander
http://www.ghisler.com

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 36549
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 9.20] Empty environment variables are broken

Post by *ghisler(Author) » 2018-08-01, 16:39 UTC

This should work now in RC2, please test it!
Author of Total Commander
http://www.ghisler.com

User avatar
MVV
Power Member
Power Member
Posts: 8142
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Re: [TC 9.20] Empty environment variables are broken

Post by *MVV » 2018-08-02, 05:12 UTC

Thank you very much, works like a charm! :D

User avatar
LonerD
Senior Member
Senior Member
Posts: 292
Joined: 2010-06-19, 20:18 UTC
Location: Donetsk

Re: [TC 9.20] Empty environment variables are broken

Post by *LonerD » 2018-08-05, 18:25 UTC

Thank you :)
Total Commander DreamLair - dream always, think totally, be the commander of you own life.

Post Reply