This forum uses cookies. Click X button to hide this message. What is stored? / Privacy
Total Commander Forum Index Total Commander
Forum - Public Discussion and Support
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TC cannot correctly resolve some predefined variables

 
Post new topic   Reply to topic    Total Commander Forum Index -> Total Commander (English) Printable version
View previous topic :: View next topic  
Author Message
Sysman
Junior Member
Junior Member


Joined: 08 Jun 2018
Posts: 6

PostPosted: Fri Jun 08, 2018 4:47 am    Post subject: TC cannot correctly resolve some predefined variables Reply with quote

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.
Back to top
View user's profile Send private message
Sysman
Junior Member
Junior Member


Joined: 08 Jun 2018
Posts: 6

PostPosted: Fri Jun 08, 2018 4:54 am    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
Stefan2
Power Member
Power Member


Joined: 13 Sep 2007
Posts: 1928
Location: Europa

PostPosted: Fri Jun 08, 2018 5:19 am    Post subject: Reply with quote

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.
_________________
The destination is one thing. Getting there is everything.
Back to top
View user's profile Send private message
Sysman
Junior Member
Junior Member


Joined: 08 Jun 2018
Posts: 6

PostPosted: Fri Jun 08, 2018 5:29 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Stefan2
Power Member
Power Member


Joined: 13 Sep 2007
Posts: 1928
Location: Europa

PostPosted: Fri Jun 08, 2018 6:38 am    Post subject: Reply with quote

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.






 
_________________
The destination is one thing. Getting there is everything.
Back to top
View user's profile Send private message
Sysman
Junior Member
Junior Member


Joined: 08 Jun 2018
Posts: 6

PostPosted: Fri Jun 08, 2018 7:13 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Stefan2
Power Member
Power Member


Joined: 13 Sep 2007
Posts: 1928
Location: Europa

PostPosted: Fri Jun 08, 2018 8:06 am    Post subject: Reply with quote

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




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







 
_________________
The destination is one thing. Getting there is everything.
Back to top
View user's profile Send private message
Horst.Epp
Power Member
Power Member


Joined: 06 Feb 2003
Posts: 2922
Location: Germany

PostPosted: Fri Jun 08, 2018 8:43 am    Post subject: Reply with quote

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 x64 Version 1803
April 2018 Update (OS Build 17134.112)
TC 9.20rc2 x64 and x86
Back to top
View user's profile Send private message
Sysman
Junior Member
Junior Member


Joined: 08 Jun 2018
Posts: 6

PostPosted: Fri Jun 08, 2018 1:35 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
Stefan2
Power Member
Power Member


Joined: 13 Sep 2007
Posts: 1928
Location: Europa

PostPosted: Fri Jun 08, 2018 1:54 pm    Post subject: Reply with quote

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





 
_________________
The destination is one thing. Getting there is everything.
Back to top
View user's profile Send private message
MVV
Power Member
Power Member


Joined: 03 Aug 2008
Posts: 8037
Location: Russian Federation

PostPosted: Fri Jun 08, 2018 1:55 pm    Post subject: Reply with quote

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:
Command: "%COMMANDER_PATH%\Extras\testPar.wsf" /param:"%COMMANDER_PATH%\Extras\test.xml"
Parameters:

Code:
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)

_________________
TCFS2 + TCFS2Tools: Full-screen mode for TC etc (forum)
TOTALCMD.NET: AskParam, CopyTree, NTLinks, Sudo, VirtualPanel…
Back to top
View user's profile Send private message Send e-mail
Sysman
Junior Member
Junior Member


Joined: 08 Jun 2018
Posts: 6

PostPosted: Fri Jun 08, 2018 2:25 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
MVV
Power Member
Power Member


Joined: 03 Aug 2008
Posts: 8037
Location: Russian Federation

PostPosted: Fri Jun 08, 2018 10:57 pm    Post subject: Reply with quote

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.
_________________
TCFS2 + TCFS2Tools: Full-screen mode for TC etc (forum)
TOTALCMD.NET: AskParam, CopyTree, NTLinks, Sudo, VirtualPanel…
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Total Commander Forum Index -> Total Commander (English) All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Imprint/Impressum: This site is maintained by Ghisler Software GmbH
Privacy Policy | Datenschutzerklärung | Politique de Confidentialité

Using phpBB © phpBB Group