+Env variables in command in button

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

Moderators: Hacker, petermad, Stefan2, white

Post Reply
HBB
Senior Member
Senior Member
Posts: 295
Joined: 2008-05-05, 21:31 UTC

+Env variables in command in button

Post by *HBB »

A test script (Test.vbs) which shows first two arguments:
msgbox WScript.Arguments(0)
msgbox WScript.Arguments(1)

A Button which runs Test.vbs:
Command: "Path\To\Test.vbs" "%comspec%" "%comspec%"
=> display environment variables as expected

If first argument of the Command is changed to a nonexistent env variable:
Command: "Path\To\Test.vbs" "%comspes%" "%comspec%"
=> display first argument as %comspes% as expected (because it does not exist)
=> display second argument again as %comspec% as not expected (because it exists!)

Regards
User avatar
karlchen
Power Member
Power Member
Posts: 4605
Joined: 2003-02-06, 22:23 UTC
Location: Germany

Post by *karlchen »

Hello, HBB.

Code: Select all

Command: "Path\To\Test.vbs" "%comspes%" "%comspec%"
Problem reproduced and extended!
It does not only affect the buttonbar.
It can also be reproduced by pasting the command into the Total Commander commandline.
If, however, you run the same command inside cmd.exe, it will work as expected.

Environment:
Windows Server 2008 R2 SP1
Total Commander 8.51ß3 64-bit

Cheers,
Karl
MX Linux 21.3 64-bit xfce, Total Commander 11.50 64-bit
The people of Alderaan keep on bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine.
The Prophet's Song
User avatar
white
Power Member
Power Member
Posts: 5815
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

[EDIT]The following statement is not true! See the discussion below.[/EDIT]

It has nothing to do with Total Commander. Total Commander does not resolve environment variables in the command field.

Replace "Path\To\Test.vbs" with: cmd.exe /k echo
You will see that works fine.
Last edited by white on 2014-03-19, 17:30 UTC, edited 1 time in total.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Not confirmed.

Tested with button:

Code: Select all

Command: cmd.exe /k echo %comspes% %comspec%
And console output was:

Code: Select all

%comspes% C:\Windows\system32\cmd.exe
Just as expected.

Win7x64, TC 8.51b3x32.
User avatar
karlchen
Power Member
Power Member
Posts: 4605
Joined: 2003-02-06, 22:23 UTC
Location: Germany

Post by *karlchen »

white wrote:It has nothing to do with Total Commander.
It has to do with Total Commander. Very likely with the API function which T.C. passes the commandlines to for execution.

Open cmd.exe and paste the complete commandline

Code: Select all

"Path\To\Test.vbs" "%comspes%" "%comspec%"
there.

First message box displays the string %comspes%.
Second message box displays the expanded variable %comspec%, i.e. its content.

But when invoked from inside T.C. the second variable %comspec% is not expanded and displayed as the string %comspec%

Diagnosis:
The first non-existing variable on a commandline will prevent any further valid variable name from being expanded, in case the commandline is launched from inside T.C., buttonbar or commandline bar.

Karl
MX Linux 21.3 64-bit xfce, Total Commander 11.50 64-bit
The people of Alderaan keep on bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine.
The Prophet's Song
HBB
Senior Member
Senior Member
Posts: 295
Joined: 2008-05-05, 21:31 UTC

Post by *HBB »

white wrote:
It has nothing to do with Total Commander.
Author wrote in topic:
Try putting the parameters in the command field, e.g.
"c:\windows\notepad.exe" "%homedir%\filename.txt"

TC will resolve env vars in the command field, and placeholders in the parameters field.
User avatar
white
Power Member
Power Member
Posts: 5815
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

karlchen wrote:Diagnosis:
The first non-existing variable on a commandline will prevent any further valid variable name from being expanded, in case the commandline is launched from inside T.C., buttonbar or commandline bar.
OK. I was wrong.

It works correctly when using Windows Run to execute: "c:\temp\vbs\test.vbs" "%comspes%" "%comspec%"
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I have checked it now - the function indeed stops replacing environment variables on the first error (variable not found). I have changed that now, please try it!
Author of Total Commander
https://www.ghisler.com
HBB
Senior Member
Senior Member
Posts: 295
Joined: 2008-05-05, 21:31 UTC

Post by *HBB »

Checked TC8.51B4 x64 & x32 on Win7 x64 => OK. It works well.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Thanks!
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 5815
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

Tested OK using TC8.51b4 32bit.
User avatar
white
Power Member
Power Member
Posts: 5815
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

Process Monitor shows:

Code: Select all

23:05:37,7292721	TOTALCMD.EXE	2000	QueryDirectory	C:\temp\vbs\test.vbs .%comspes%..*	NO SUCH FILE	Filter: test.vbs .%comspes%..*
23:05:37,7294187	TOTALCMD.EXE	2000	CloseFile	C:\temp\vbs	SUCCESS	
23:05:37,7296581	TOTALCMD.EXE	2000	QueryOpen	C:\temp\vbs\test.vbs "%comspes%"	NAME INVALID	
23:05:37,7298957	TOTALCMD.EXE	2000	QueryOpen	C:\temp\vbs\test.vbs	SUCCESS	<cut>
It seems that quotes are replaced by dots and a file matching C:\temp\vbs\test.vbs .%comspes%..* is searched. Is this a bug or correct?

If you use parameter "hello" instead of "comspes":

Code: Select all

23:13:15,4885718	TOTALCMD.EXE	2000	QueryDirectory	C:\temp\vbs\test.vbs .hello..*	NO SUCH FILE	Filter: test.vbs .hello..*
23:13:15,4886936	TOTALCMD.EXE	2000	CloseFile	C:\temp\vbs	SUCCESS	
23:13:15,4888779	TOTALCMD.EXE	2000	QueryOpen	C:\temp\vbs\test.vbs "hello"	NAME INVALID	
23:13:15,4890883	TOTALCMD.EXE	2000	QueryOpen	C:\temp\vbs\test.vbs	SUCCESS	<cut>
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50541
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

2white
I guess that this is done by Windows because you didn't put the command in double quotes, so Windows has to determine first where the program name ends.
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 5815
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Post by *white »

ghisler(Author) wrote:2white
I guess that this is done by Windows because you didn't put the command in double quotes, so Windows has to determine first where the program name ends.
OK. You are right that I did not put quotes around the command. I thought TC was trying to determine where the program ends. So this is done by an API call?

BTW. If I run the same command using Windows Run, it does not happen.
Post Reply