The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
sergiokapone
Junior Member
Junior Member
Posts: 39
Joined: 2017-01-17, 07:45 UTC

The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *sergiokapone »

I changed the %ComSpec% system variable to new value of d:\Programs\Utility\WindowsTerminal\wt.ext cmd.exe to open Windows Terminal, and Total Commander gave an error when calling cm_ExecuteDOS:

Code: Select all

[Window Title]
d:\Programs\Utility\WindowsTerminal\wt.exe cmd.exe

[Content]
Cannot find "d:\Programs\Utility\WindowsTerminal\wt.exe cmd.exe". Check if the name is correct and try again.

[ОК]
I don't understand why in this case TC can't just run wt.exe cmd.exe. What prevents it from doing so?


I can note that if TC explicitly (on the button) starts a console application (.exe) or .cmd/.bat file, the Windows Terminal is invoked quite normally.
Russian Language of Total Commander
Windows 10 Core 10.0 (Build 19045), base: 0400000
User avatar
Dalai
Power Member
Power Member
Posts: 9945
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *Dalai »

Well, apparently you expect a full command to work in that variable. %ComSpec% points to a simple executable by default, and honestly I don't know of any environment variable containing a full command, certainly not in stock Windows systems.

You can use a workaround and let %ComSpec% point to a batch file that contains your command, e.g. wt_cmd.cmd containing

Code: Select all

@d:\Programs\Utility\WindowsTerminal\wt.ext cmd.exe
or something similar.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
sergiokapone
Junior Member
Junior Member
Posts: 39
Joined: 2017-01-17, 07:45 UTC

Re: The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *sergiokapone »

At least the button on the panel fires normally and starts the command wt.exe cmd /k

Code: Select all

TOTALCMD#BAR#DATA
%ComSpec% /k

imageres.dll


0
-1

That is, %ComSpec% can contain a command with a parameter. Maybe the problem is related to the implementation of cm_ExecuteDOS in TC.
Russian Language of Total Commander
Windows 10 Core 10.0 (Build 19045), base: 0400000
sergiokapone
Junior Member
Junior Member
Posts: 39
Joined: 2017-01-17, 07:45 UTC

Re: The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *sergiokapone »

I know that in the new Win10 and Win11 updates you can select the default terminal. Unfortunately, in my version it is not possible. But I wonder, if I choose the default WT, will there also be an error in executing cm_ExecuteDOS, or is everything normal there?
Russian Language of Total Commander
Windows 10 Core 10.0 (Build 19045), base: 0400000
User avatar
Dalai
Power Member
Power Member
Posts: 9945
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Re: The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *Dalai »

It's likely that TC checks if the executable pointed to by %ComSpec% exists. And that fails for a full command. Ghisler can probably explain it in more detail how it's implemented and why it is the way it is.
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
white
Power Member
Power Member
Posts: 5747
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *white »

sergiokapone wrote: 2024-11-15, 16:37 UTC I know that in the new Win10 and Win11 updates you can select the default terminal. Unfortunately, in my version it is not possible. But I wonder, if I choose the default WT, will there also be an error in executing cm_ExecuteDOS, or is everything normal there?
Normal of course, because then %ComSpec% is not changed.

%ComSpec% shouldn't contain parameters. It's only meant to locate the command line interpreter. So the error is normal.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50390
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: The cm_ExecuteDOS command does not work when the %ComSpec% value is changed

Post by *ghisler(Author) »

TC calls ShellExecuteExW with the command. However, since there is a space in the command, it puts it in double quotes to avoid ambiguities, so the program cannot be found.

Try setting comspec to:
"d:\Programs\Utility\WindowsTerminal\wt.exe" cmd.exe

Then Total Commander doesn't add its own double quotes.
Author of Total Commander
https://www.ghisler.com
Post Reply