Total Commander doesn't honor Windows' PATH variable

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
r4czek
Junior Member
Junior Member
Posts: 3
Joined: 2020-07-13, 11:58 UTC

Total Commander doesn't honor Windows' PATH variable

Post by *r4czek »

Dear All,

I'm struggling with a following problem. I can't seem to force a Total Commander to honor my Window's PATH environment variable, when using TC's built-in command prompt.

I have 3 instances of bash executable installed, provided by 3 different entities (Cygwin, Windows Subsystem for Linux and git-bash). When I open Window's Command Prompt, I observe following behavior:

Code: Select all

> where bash
C:\cygwin64\bin\bash.exe
C:\Windows\System32\bash.exe
C:\Program Files\Git\usr\bin\bash.exe

> bash
(cygwin's bash opens)
So far so good.

Unfortunately, running the very same command (bash) from TC's command prompt (at the bottom of the window), yields different result:

Code: Select all

c:\>bash
(Windows Sybsystem for Linux's bash is opened)
Am I missing something? How does TotalCommander figures out the order of precedence? Is Windows' path taken into consideration?

Context: Total Commander Version 9.51 64 bit (2020-03-25), Windows 10 64-bit
PATH System variable:

Code: Select all

C:\cygwin64\bin
[...]
%SystemRoot%\system32
[...]
C:\Program Files\Git\usr\bin
[...]
User avatar
nsp
Power Member
Power Member
Posts: 1951
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Total Commander doesn't honor Windows' PATH variable

Post by *nsp »

If you run TC with the same user, and without changing the path in an autorun script the path should be the same as one of the shell taking . into account.

A) Verify that you no not have any alias for bash...

B) As TC do not do any fancy stuff when launching a process, only using win api... You can run CMD from Command line and then verify PATH variable and which bash is then selected from prompt.

If you want to be sure the best is to define an alias targetting full path !
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50873
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Total Commander doesn't honor Windows' PATH variable

Post by *ghisler(Author) »

According to Microsoft's documentation, the function ShellExecuteEx searches for executables in the following order:

1. The current working directory.
2. The Windows directory only (no subdirectories are searched).
3. The Windows\System32 directory.
4. Directories listed in the PATH environment variable.
5. Recommended: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

You can find it here (under: Finding Application Executable):
https://docs.microsoft.com/de-de/windows/win32/shell/app-registration?redirectedfrom=MSDN

So according to this,
C:\Windows\System32\bash.exe
Author of Total Commander
https://www.ghisler.com
r4czek
Junior Member
Junior Member
Posts: 3
Joined: 2020-07-13, 11:58 UTC

Re: Total Commander doesn't honor Windows' PATH variable

Post by *r4czek »

nsp wrote: 2020-07-13, 12:37 UTC A) Verify that you no not have any alias for bash...
I'm by no means fluent in Windows' aliases. I haven't defined a single one explicitly, that for sure.
With a help of https://superuser.com/questions/1071883/how-do-i-check-the-current-cmd-aliases, I've run

Code: Select all

>doskey /MACROS:ALL
in freshly opened cmd and got an empty result. So I suppose I got no aliases set?


nsp wrote: 2020-07-13, 12:37 UTC B) As TC do not do any fancy stuff when launching a process, only using win api... You can run CMD from Command line and then verify PATH variable and which bash is then selected from prompt.
Yep, I've tried that already. Running

Code: Select all

C:\>cmd
in TotalCommander, and then, immediately

Code: Select all

>bash
within newly opened command prompt, a desired, cygwin bash is opened.


nsp wrote: 2020-07-13, 12:37 UTC If you want to be sure the best is to define an alias targetting full path !
I'll explore that idea and report as soon as I get any result!
User avatar
nsp
Power Member
Power Member
Posts: 1951
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Total Commander doesn't honor Windows' PATH variable

Post by *nsp »

I do not mean doskey allias but rather TC allias the one you define in Preferences -> Configuration -> Misc
allias field.
r4czek
Junior Member
Junior Member
Posts: 3
Joined: 2020-07-13, 11:58 UTC

Re: Total Commander doesn't honor Windows' PATH variable

Post by *r4czek »

@ghisler
Thanks a lot, that explains everything.

In that case I went with what @nsp suggested and added a new alias to explicitly use cygwin's bash.

For future reference, this is what did a trick for me:

Code: Select all

1. Open TotalCommander
2. Go to Configuration > Options > Misc.
3. In the "Redefine hotkeys (Keyboard remapping)" area click:
    i. Select "Alias" radio button
    ii. Write "bash" in the first text input
    iii. Click a magnifying glass icon
4. In the "Choose command" window:
    i. Select "usercmd.ini" from the left-hand side list.
    ii. Hit "New..."
    iii. Command name: "em_bash"
    iv. Command: C:\cygwin64\bin\bash.exe and leave other inputs empty
    v. Hit "Ok"
5. Back in Configuration window, hit green tick icon
Done!
Thanks a lot! :)
Post Reply