Percent sign doubling in cmd-line

Please report only one bug per message!

Moderators: Stefan2, white, sheep, Hacker

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

Percent sign doubling in cmd-line

Post by *MVV » 2009-09-04, 06:49 UTC

When I write in command or parameter field something like %%WINDIR%% or %%COMMANDER_PATH%%, TC interprets it as normal environment variable and expands.

Expected that TC will expand %WINDIR% to Windows path but leave %%WINDIR%% as is.

TC 7.5 RC2

For test:
1. create buttonbar button
2. type in cmd: cmd /k echo cmd {1:%COMMANDER_PATH%} {2:%WINDIR%} {3:%%COMMANDER_PATH%%} {4:%%WINDIR%%}
3. type in param: param {1:%COMMANDER_PATH%} {2:%WINDIR%} {3:%%COMMANDER_PATH%%} {4:%%WINDIR%%}
4. choose any icon
5. start button

You will see that TC expands all enrironment variables (for 3, 4 in cmd TC leaves extra %-signs). But it should expand only strings with single-percent signs!


Another bug with this fields:
TC don't pass all parameters to cmd, with my button described above I don't see word 'param' and following parameters at all (if some envvars have big length). If I move all params in cmd field, it works well, if I leave half of them (or all) in param field, TC doesn't pass all params to program. Maybe some parameter buffer too small?

For test:
0. copy TC to folder like "F:\TEMP\1st folder\myfolder\programs\TOTALCMD\"
1-5. same as in prev step

You will see that TC doesn't show all params. I see following:

Code: Select all

cmd {1:F:\TEMP\1st folder\myfolder\programs\TOTALCMD} {2:C:\Windows} {3:%F:\TEMP
\1st folder\myfolder\programs\TOTALCMD%} {4:%C:\Windows%}
Last edited by MVV on 2009-09-04, 16:22 UTC, edited 5 times in total.

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-04, 07:49 UTC

Doesn't TC handle a couple of its "own" variables slightly differently than a normal Environment variable?
Like, doesn't this happen with pretty much every Environment variable, such as, %ProgramFiles%, %WINDIR%, etc... but not with %Commander_Path%, %Commander_Drive%, etc.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.

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

Post by *MVV » 2009-09-04, 08:03 UTC

AFAIK, %COMMANDER_PATH% is an usual environment variable and you may see it through SET command (of course, only if you launch command line from TC's environment). My experiments just confirm this. And no problems with it. The problem is why TC ignores double-percent signs and treats %%COMMANDER_PATH%% or %%WINDIR%% just as environment variable (in cmd line with extra %-signs before and after).
It is strange that cmd and param fields are processed in separate functions, in my mind there should be a function like ExpandString which will process input string and perform %ENVVARS% and %PARAMS expanding (and call filelist creation function and replace %L param with filelist path if string contains some of %L-params).

Another strange thing: in param field TC incorrectly processes %-enclosed strings at all! %%COMMANDER_PATH%% it expands as envvar, but %COMMANDER_PATH% it converts to something like OMMANDER_PATH.

I think TC should check if current param ends with '%' and if yes, process it as envvar, else process it as %-param. Also if '%' is doubled, TC should just remove '%%' and leave contents untouched.

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-04, 09:05 UTC

There was something about that, possibly in the help file, or a thread(or two) about the syntax.

In Command: (line, buttons) normal expansion of %Vars%
In Parameters: (line, buttons) requires double %% or %$VARS$%

Though I thought that was no longer required. Granted I probably only use %VARS% on the "Command:" of buttons, and/or pass it all off to MultiFileOpen.cmd or such.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.

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

Post by *MVV » 2009-09-04, 16:04 UTC

This is standard to enclose environment variables in %-signs, and to double %-sign to insert '%'. So I think TC should follow it. Or at least TC should have own standard for all strings. Currently TC processes %-sign in one way in command line field and in another way in param field.

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-04, 22:32 UTC

http://ghisler.ch/board/viewtopic.php?p=174364#174364

In parameters field % signs have to be doubled for environment vars, because %P%N would otherwise treat %P% as system variable instead of internal parameters %P and %N.
You could argument that the command field should then behave the same way - but isn't it more useful to leave this at "standard" behavior?
MVV wrote:When I write in command or parameter field something like %%WINDIR%% or %%COMMANDER_PATH%%, TC interprets it as normal environment variable and expands.
I'm not sure this can be told with the test method you described. Try typing

Code: Select all

echo %%windir%%
in a console window - cmd.exe will return "%C:\Windows%" here, too - even in a batch containing this and having "echo on", this is expanded before displaying.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-04, 22:32 UTC

MVV wrote:Another bug with this fields:
TC don't pass all parameters to cmd
With your example TC passes no parameters at all.
Cause: "%WINDIR%" seem to collide with internal param "%W*" - just add a space after the first % sign of parameter 2 and you'll see all your parameters:

Code: Select all

{2:% WINDIR%}
Does this qualify as a bug?
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

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

Post by *MVV » 2009-09-05, 08:59 UTC

StatusQuo wrote:Cause: "%WINDIR%" seem to collide with internal param "%W*" - just add a space after the first % sign of parameter 2 and you'll see all your parameters:

Code: Select all

{2:% WINDIR%}
Does this qualify as a bug?
But why this works normally for "F:\TOTALCMD" and doesn't work for "F:\TEMP\1st folder\myfolder\programs\TOTALCMD"?
If it is not a bug, it should work in same way for any variables contents.
StatusQuo wrote:I'm not sure this can be told with the test method you described. Try typing

Code: Select all

echo %%windir%%
in a console window - cmd.exe will return "%C:\Windows%" here, too - even in a batch containing this and having "echo on", this is expanded before displaying.
Well, I checked, TC passes to cmd.exe command line:

Code: Select all

"C:\Windows\System32\cmd.exe" /k echo %%COMMANDER_PATH%%
And cmd.exe shows:

Code: Select all

%E:\TOTALCMD%
But question remains: how to pass to program exactly string "%COMMANDER_PATH%" e.g.? If I specify "%COMMANDER_PATH%" in cmd field, I get E:\TOTALCMD in parameter of application, if I specify "%%COMMANDER_PATH%%" in cmd field, I get "%%COMMANDER_PATH%%". If TC expands %BLABLABLA% as environment variable, it should treat double percent sign as ordinary.

Yes, with echo from cmdline situation is clear, but try to create bat-file:

Code: Select all

@echo %TEMP%
@echo %%TEMP%%
When I execute file, I see:

Code: Select all

F:\TEMP
%TEMP%
So, all work as expected for bat-files.
StatusQuo wrote:You could argument that the command field should then behave the same way - but isn't it more useful to leave this at "standard" behavior?
If all fields will have similar syntax, it will be easier for user, and we will have to have only one piece of code for processing this.

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-05, 16:37 UTC

MVV wrote:how to pass to program exactly string "%COMMANDER_PATH%"
"%%COMMANDER_PATH%%" in parameters field to pass without expanding?

Tested with a little TestParam.exe, used instead of "cmd.exe /k" in your example:
Param 0: F:\TEMP\1st folder\myfolder\programs\TOTALCMD\Tools\TestParam\TestParam.exe
Param 1: cmd
Param 2: {1:F:\TEMP\1st
Param 3: folder\myfolder\programs\TOTALCMD}
Param 4: {2:C:\WINDOWS}
Param 5: {3:%%COMMANDER_PATH%%}
Param 6: {4:%%WINDIR%%}
Param 7: param
Param 8: {1:OMMANDER_PATH
Param 9: {2:WINDIR
Param 10: {3:%COMMANDER_PATH%}
Param 11: {4:%WINDIR%}
<press any key>
MVV wrote:But why this works normally for "F:\TOTALCMD" and doesn't work for "F:\TEMP\1st folder\myfolder\programs\TOTALCMD"?
Can't reproduce that, TC is passing+printing the parameters from both paths here when using "% WINDIR%", and is not for "%WINDIR%".
Maybe missing double quotes around "%COMMANDER_PATH%" cause a problem for the TC path containing spaces?
MVV wrote:If all fields will have similar syntax, it will be easier for user, and we will have to have only one piece of code for processing this.
AFAIS, in command field system variables are expanded, while internal ones are not.
The parameters field works the opposite way. Not sure, if the syntax can be made easier.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom » 2009-09-05, 17:06 UTC

MVV wrote: But question remains: how to pass to program exactly string "%COMMANDER_PATH%" e.g.? If I specify "%COMMANDER_PATH%" in cmd field, I get E:\TOTALCMD in parameter of application, if I specify "%%COMMANDER_PATH%%" in cmd field, I get "%%COMMANDER_PATH%%". If TC expands %BLABLABLA% as environment variable, it should treat double percent sign as ordinary.
If yer trying to send it to .cmd ? then this will do it:
either:
command: cmd /k echo %^COMMANDER_PATH%
OR:
command: cmd /k echo
parameters: %%^COMMANDER_PATH%%

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

Post by *MVV » 2009-09-06, 10:42 UTC

Well, I tested it with my MessageBox.exe:

Code: Select all

MIME-Version: 1.0
Content-Type: application/octet-stream; name="MessageBox.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="MessageBox.zip"

UEsDBBQAAgAIAE1kHjsCJJkdggEAAAAKAAAOAAAATWVzc2FnZUJveC5leGXzjZrAwMzAwMACxP//
MzDsYIAABwbCYAMQ88nv4mPYwnlWcQejz1nFkIzMYoWCovz0osRcheTEvLz8EoWkVIWi0jyFzDwF
F/9ghdz8lFQ9Xl4uFagZsal/T0iyTJ4Nw9OlG2YLAumnKo2zJYB0UGZyBkgcZmeAKwODDyMzw2TL
WV4wsQcM/IzcjKw8DExQj4CAABQrQH0DYjMhpGE02KNQDhNMowAyDafAQARong0DDQDQXBE80nol
qRUlIBrmIGS/IoxI0CtKSSxJZGBYAxUAq2NDVQf0soMeRBkDL0jAAKqOA0PdAYZRMKxBlkMGg4ED
wwsxUN7KYngBSoNAihFInfmvyqLgwPBflQFM8ig4jAbXsANFwDIiRQHCngSlAxQQ8i0KkHIkBkls
AZDNo0C8eQ0MrhWZJQFF+cmpxcUMJxjcU0uc83NzE/NSfDLzUh0ZslOL8lJzjI30UnJyGBjmMvoC
lSWmpzrlVzgylBanFsFkRgH1ATQiFEAxMRoaIw8AAFBLAQIUABQAAgAIAE1kHjsCJJkdggEAAAAK
AAAOAAAAAAAAAAAAIAAAAAAAAABNZXNzYWdlQm94LmV4ZVBLBQYAAAAAAQABADwAAACuAQAAAAA=
In parameters field I can type "%%COMMANDER_PATH%%", and MessageBox shows that string "%COMMANDER_PATH%" was passed as I need. But in command field I can't.
Balderstrom wrote:
command: cmd /k echo %^COMMANDER_PATH%
That's interesting...

StatusQuo
Power Member
Power Member
Posts: 1465
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo » 2009-09-07, 00:43 UTC

MVV wrote:In parameters field I can type "%%COMMANDER_PATH%%", and MessageBox shows that string "%COMMANDER_PATH%" was passed as I need. But in command field I can't.
Confirmed. Translating "%%" to "%" also in command field would be better, if possible.
StatusQuo wrote:AFAIS, in command field system variables are expanded, while internal ones are not.
The parameters field works the opposite way.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!

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

Post by *MVV » 2009-09-07, 03:57 UTC

All was easier when cmd field contained just executable file name. :)
Perhaps same thing should have been used for commands like SYNCOPEN - parameter should have been accepted in parameters field.

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

Post by *ghisler(Author) » 2009-09-07, 14:31 UTC

I can confirm the problem now. In TC 7.5, I will replace %% by % and leave the variable unchanged. Unfortunately this may break some user's buttons because the behaviour will be different from older versions, but it seems to be more logical to me.
Author of Total Commander
http://www.ghisler.com

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

Post by *ghisler(Author) » 2009-09-08, 06:17 UTC

Unfortunately I have to keep the behaviour of TC 7.5 RC2 and older for now. Why? Immagine a directory named a%%b or even a%%b%%c. Users may be accessing the second directory via a button
cd a%%b%%c
which works fine now as long as there is no variable %b%. Replacing the double % sign by a single one would break this functionality. Therefore we need to find a rule set how to handle this, depending on whether a variable 'b' exists or not, in a way which is logical to the user. There isn't enough time to do that before the release of TC 7.5 final, but I want to start the discussion now.

Possible solutions:
1. Always replace %% by %, and leave the env. var in between alone, e.g.
a%%b -> a%b
a%%b%%c -> a%b%c

2. Only look for pairs of double percents, as in the second name, and replace only those, e.g.
a%%b -> a%%b (unchanged)
a%%b%%c -> a%b%c

3. Only look for pairs of double percents, as in the second name, but replace them only if the env. var really exists, e.g.
a%%b -> a%%b (unchanged)
a%%b%%c -> a%%b%%c (also unchanged)
a%%temp%%c -> a%temp%c
Author of Total Commander
http://www.ghisler.com

Post Reply