Button: CD doesn't follow envvars if used in Parameters

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Button: CD doesn't follow envvars if used in Parameters

Post by *DrShark »

Update from March 19, 2018:
Original report was about not working %var% in button Parameters field.
It was explained below why it shouldn't work.

However, it is expected that %% in Parameters field should work as % in Command field, so %%var%% in Parameters field should work. And it works for external programs in Command field, but it doesn't work for internal cd command (it doesn't matter how %%var%% appears in Parameters field: written directly, transferred by input dialog called by ? mark or by %A parameter of user command).
Original report from Aug 28, 2017 wrote:To reproduce (tested in current final TC 9.0a 32 bit):
1. Make a button with cd as command and ? as a parameter, like this one:

Code: Select all

TOTALCMD#BAR#DATA
cd
?
%COMMANDER_EXE%,6
GoEnvVar


-1
2. Use this button, in a dialog that will appear enter environment variable or pseudo environment variable and confirm it.
It's expected that TC then will switch to the path of environment variable, but instead nothing happens.
Last edited by DrShark on 2018-03-19, 08:57 UTC, edited 2 times in total.
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Unfortunately you cannot use environment variables in the parameters field, only in the "command" field. They would clash with internal placeholders like %P or %N.

Furthermore, placeholders are evaluated BEFORE the ? takes effect, e.g. when you specify ?%T, TC will show a dialog box with the directory from the target panel.
Author of Total Commander
https://www.ghisler.com
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

Maybe to solve this you can consider to add support for escaped variable, like %%COMMANDER_PATH%%, to internal cd, md etc. commands? It already works if third party app like cmd.exe is used in Command field of a button.
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

Why you decided not to use variables escaping for internal cd command in parameters while it works for external applications - there it doesn't seem to cause problems with internal placeholders like %P or %N.
I mean, it's inconsistent that following works:

Code: Select all

TOTALCMD#BAR#DATA
cmd /k echo
?%%commander_path%%
%COMSPEC%



-1
and following doesn't:

Code: Select all

TOTALCMD#BAR#DATA
cd
?%%commander_path%%
%COMMANDER_EXE%



-1
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Because %x is a parameter but %% inserts % character.
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

MVV wrote:%% inserts % character.
Yes, it is. Please note that topic is about a button with dialog (? mark as a first character in a Parameters field), that's why %% used in my above examples.
There a button with cmd.exe works (echo expands correct variable). But a button with cd command and same parameter doesn't work - I wonder what may be a reason.
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

There a button with cmd.exe works
Because cmd.exe expands variables in its command line.
But a button with cd command and same parameter doesn't work
Because TC doesn't expand variables after ? dialog.

If you really want to use cd with dialog, you can e.g. use my TCFS2, it supports cd command and it expands variables in parameters:

Code: Select all

Command: TCFS2.exe /ef
Parameters: "tcd(`?`,,S)"
Also you can join it with my AskParam for cleaner input field w/o other command line:

Code: Select all

Command: AskParam.exe
Parameters: /t"%TEMP%" /p"Path:" TCFS2.exe /ef "tcd(`%1`,,S)"
User avatar
DrShark
Power Member
Power Member
Posts: 1872
Joined: 2006-11-03, 22:26 UTC
Location: Kyiv, 68/262
Contact:

Post by *DrShark »

2MVV
It's really good that this can be solved by 3rd party tools, thanks.

But it is really expected that %%var%% in Parameters field should work for internal cd command too, because currently there is no built-in way to pass a variable to it from Parameters field. I have changed topic title and the first post so it has actual information on the problem now.
Donate for Ukraine to help stop Russian invasion!
Ukraine's National Bank special bank account:
UA843000010000000047330992708
Post Reply