TC cannot correctly resolve some predefined variables

English support forum

Moderators: white, sheep, Hacker, Stefan2

Post Reply
Sysman
Junior Member
Junior Member
Posts: 6
Joined: 2018-06-08, 09:56 UTC

TC cannot correctly resolve some predefined variables

Post by *Sysman » 2018-06-08, 10:47 UTC

Predefined variable "%COMMANDER_PATH%" in "Parameters" cannot be resolved correctly.

Preconditions: Install TC to "C:\Program Files\totalcmd"

Steps to Reproduce:

1. Create new folder with path "C:\Test"
2. Run TC and navigate in active panel to folder "C:\Test"
3. Create under TC installation directory new folder with name "Extras"
4. Copy test script testPar.wsf inside this folder
5. In the TC's toolbar add new single button with the following:
Command: %COMMANDER_PATH%\Extras\testPar.wsf
Parameters: /param:"%COMMANDER_PATH%\Extras\test.xml"
6. After adding new button, click on it.
7. Check path passed in parameters.

Expected Result:
The path is: C:\Program Files\totalcmd\Extras\test.xml

Actual Result:
The path is: C:\Test\..OMMANDER_PATHExtras\test.xml

_______________________________________________________
Test environment: Windows 10, x64-based system

Tested on trial TCs with v9.12 (latest final as of the current date) and v9.20B6 (latest beta as of the current date).

Thus, predefined variable "%COMMANDER_PATH%" in "Command" will be resolved correctly, but in "Parameters" it is not.

It looks like "%C" in "%COMMANDER_PATH% is replaced by current path.

Sysman
Junior Member
Junior Member
Posts: 6
Joined: 2018-06-08, 09:56 UTC

Post by *Sysman » 2018-06-08, 10:54 UTC

Also I'm not able to post test script now, due to the forum restrictions, but I will try to post in day later (if it will be needed to reproduce, this script only shows parameter which passed to it).

User avatar
Stefan2
Power Member
Power Member
Posts: 2183
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 » 2018-06-08, 11:19 UTC

Hi and welcome.

Please follow the rules of MS-DOS and double the per-cent signs if used in Parameter box.


Command: cmd /k
Parameters: ECHO %Commander_Path% & ECHO %%Commander_Path%%


For you, TC have seen "%C", which is an parameter on its own. (Next then TC gets "ommander_Path" and "%\" as parameters)
(open an button for modifying, then press F1 and read more at the help)


Also, for your case, best use quotes in Command box too.

Sysman
Junior Member
Junior Member
Posts: 6
Joined: 2018-06-08, 09:56 UTC

Post by *Sysman » 2018-06-08, 11:29 UTC

Stefan2 wrote:Hi and welcome.

Please follow the rules of MS-DOS and double the per-cent signs if used in Parameter box.


Command: cmd /k
Parameters: ECHO %Commander_Path% & ECHO %%Commander_Path%%


For you, TC have seen "%C", which is an parameter on its own. (Next then TC gets "ommander_Path%" as parameter)
(open an button for modifying, then press F1 and read more at the help)


Also, for your case, best use quotes in Command box too.
Double the per-cent signs works for your simple case with command window, but still doesn't work in described bug.
After double the per-cent signs I have the following result:
The path is: %COMMANDER_PATH%\Extras\test.xml

User avatar
Stefan2
Power Member
Power Member
Posts: 2183
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 » 2018-06-08, 12:38 UTC

Sysman wrote:
Stefan2 wrote:.
Double the per-cent signs works for your simple case with command window, but still doesn't work in described bug.
After double the per-cent signs I have the following result:
The path is: %COMMANDER_PATH%\Extras\test.xml
Well, as far as I remember, it's up to the called app to resolve (expand) the env var.

Other takers please.... Am I right?




Ahh, moment, check it with a leading '?' question-mark sign in the Parameter box

Command: cmd /k
Parameters: ? ECHO %Commander_Path% & ECHO %%Commander_Path%%

You see, TC doesn't expand that var. The called app has to do this. The commandlineinterpreter is able to do this.



- - -


Proof of example



Button:
Command: z.VBS
Parameter: %COMMANDER_PATH% # %%COMMANDER_PATH%%


z.VBS:
msgbox wscript.arguments(0) & vbLF & wscript.arguments(1)



Result:
---------------------------

---------------------------
X:\temp\z.vbsOMMANDER_PATH#
%COMMANDER_PATH%
---------------------------
OK
---------------------------



Solution:
Use smtg like
SET WSO = WScript.CreateObject("WScript.Shell")
TCPath = WSO.ExpandEnvironmentStrings("%Commander_Path%")
myPath=TCPath & "\Extras\test.xml"
in your script.






 

Sysman
Junior Member
Junior Member
Posts: 6
Joined: 2018-06-08, 09:56 UTC

Post by *Sysman » 2018-06-08, 13:13 UTC

I can agree with you, but why does then TC expand "%C" in "%COMMANDER_PATH%" in passed parameter to current path?

Therefore I consider it as a bug.

User avatar
Stefan2
Power Member
Power Member
Posts: 2183
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 » 2018-06-08, 14:06 UTC

Sysman wrote:I can agree with you, but why does then TC expand "%C" in "%COMMANDER_PATH%" in passed parameter to current path?

TC see first "%C", which is an parameter on its own.
See the help:
%C1 : First selected file, or file under cursor

Test it yourself:
Cmd: cmd /k
Para: ECHO %C & ECHO %C1



Therefore I consider it as a bug.
No, it's by design.







 

User avatar
Horst.Epp
Power Member
Power Member
Posts: 3110
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Post by *Horst.Epp » 2018-06-08, 14:43 UTC

Sysman wrote:I can agree with you, but why does then TC expand "%C" in "%COMMANDER_PATH%" in passed parameter to current path?

Therefore I consider it as a bug.
But you are the only one, its not a bug.
Its by design.
Windows 10 Home x64 October 2018 Update
Version 1809 (OS Build 17763.134)
TC 9.21a x64 and x86, Everything 1.4.1.921 (x64)

Sysman
Junior Member
Junior Member
Posts: 6
Joined: 2018-06-08, 09:56 UTC

Post by *Sysman » 2018-06-08, 19:35 UTC

You want to say me that one predefined variable (%C) is expanding in parameters, but other predefined variable (%COMMANDER_PATH%) is not, and it's not a bug, and it's all by design.
I'm confused. Could you please give me a link where I will be able to see which predefined variables are expanding in parameters?

User avatar
Stefan2
Power Member
Power Member
Posts: 2183
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 » 2018-06-08, 19:54 UTC

Sysman wrote:...Could you please give me a link where I will be able to see which predefined variables are expanding in parameters?
> https://ghisler.ch/board/viewtopic.php?p=342566#342566

> sentence no. 6





 

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

Post by *MVV » 2018-06-08, 19:55 UTC

Well, it is really not a bug but by design.

TC does expand envvars in Command field but doesn't in Parameters field, because the latter one uses %parameter syntax (a single % character and some letters/digits) which conflicts with %envvar% syntax. So you can either move part of command line with envvar to Command field or double % characters to pass them to a program unchanged, but in such case the program should be able to expand them:

Code: Select all

Command: "%COMMANDER_PATH%\Extras\testPar.wsf" /param:"%COMMANDER_PATH%\Extras\test.xml"
Parameters:

Code: Select all

Command: "%COMMANDER_PATH%\Extras\testPar.wsf"
Parameters: /param:"%%COMMANDER_PATH%%\Extras\test.xml"
As it was said, you can read about %parameters in help:
Stefan2 wrote:(open an button for modifying, then press F1 and read more at the help)

Sysman
Junior Member
Junior Member
Posts: 6
Joined: 2018-06-08, 09:56 UTC

Post by *Sysman » 2018-06-08, 20:25 UTC

Thank you. If it is by design, I will try to expand all env. vars passed in parameters in my scripts (in Windows-based scripts, function "ExpandEnvironmentStrings" works good, and it's a real solution).

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

Post by *MVV » 2018-06-09, 04:57 UTC

In such a simple example you can just put envvars in Command field. It may be hard if you need to mix both selected/focused files and envvars.

Post Reply