+Env variables in command in button
Moderators: Hacker, petermad, Stefan2, white
+Env variables in command in button
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
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
Hello, HBB.
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
Code: Select all
Command: "Path\To\Test.vbs" "%comspes%" "%comspec%"
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
The people of Alderaan keep on bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine.
The Prophet's Song
[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.
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.
Not confirmed.
Tested with button:
And console output was:
Just as expected.
Win7x64, TC 8.51b3x32.
Tested with button:
Code: Select all
Command: cmd.exe /k echo %comspes% %comspec%
Code: Select all
%comspes% C:\Windows\system32\cmd.exe
Win7x64, TC 8.51b3x32.
It has to do with Total Commander. Very likely with the API function which T.C. passes the commandlines to for execution.white wrote:It has nothing to do with Total Commander.
Open cmd.exe and paste the complete commandline
Code: Select all
"Path\To\Test.vbs" "%comspes%" "%comspec%"
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
The people of Alderaan keep on bravely fighting back the clone warriors sent out by the unscrupulous Sith Lord Palpatine.
The Prophet's Song
white wrote:
Author wrote in topic:It has nothing to do with Total Commander.
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.
OK. I was wrong.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.
It works correctly when using Windows Run to execute: "c:\temp\vbs\test.vbs" "%comspes%" "%comspec%"
- ghisler(Author)
- Site Admin
- Posts: 50541
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
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
https://www.ghisler.com
- ghisler(Author)
- Site Admin
- Posts: 50541
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Process Monitor shows:
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: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>
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>
- ghisler(Author)
- Site Admin
- Posts: 50541
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
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.
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
https://www.ghisler.com
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?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.
BTW. If I run the same command using Windows Run, it does not happen.