[TC 11.58rc1] Command line: quote added

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

Moderators: Stefan2, Hacker, petermad

Post Reply
User avatar
white
Power Member
Power Member
Posts: 6940
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

[TC 11.58rc1] Command line: quote added

Post by *white »

Suppose you're executing a command on the command line that needs cmd.exe to execute. Something more meaningful than this:

Code: Select all

cmd /c echo 123
Suppose the command doesn't give the expected result and you run the same command again but now you press Shift+Enter instead of Enter. Now the command is executed with a quote character added at the end. When running above command using Shift+Enter, the result on screen is:
123"
This is because TC runs the command using cmd.exe /K "<command>". TC adds quotes, probably because of the complex quote stripping behavior of cmd.exe when using /C or /K. Commands executed via these paramaters are not treated the same way as when they are typed in a command prompt window. The quotes added by TC are stripped in most cases, but not always. So the commands on TC's command line are still not always executed as entered by the user.

The solution would be to add parameter /S, so to use cmd.exe /S/K "<command>". This causes the quotes added by TC to always be stripped off again and for the command on TC's command line to be executed exactly as when entered in a command prompt window.

I am not sure though if parameter /S was a supported parameter for cmd.exe from the very beginning. It existed early on for sure, but whether it existed as a parameter since the first cmd.exe version, I don't know.

I don't know what currently happens when running TC on Windows 95/98 and cmd.exe is not available. TC should not add quotes when using command.com because then commands wouldn't run at all. Parameter /S and quotes around the entire command are not supported for command.com AFAIK.

There is currently also an inconsistency with the behavior when TC automatically adds "cmd.exe /C" (see here). In that case no quotes are added by TC. I think ideally quotes should be added and parameter /S should be used whenever possible in both cases:
cmd.exe /S/K "<command>"
cmd.exe /S/C "<command>"
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53138
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.58rc1] Command line: quote added

Post by *ghisler(Author) »

This is because TC runs the command using cmd.exe /K "<command>".
That's exactly what it does.
The solution would be to add parameter /S, so to use cmd.exe /S/K "<command>".
Great, that works even on Windows 2000 (just tested it).
I don't know what currently happens when running TC on Windows 95/98 and cmd.exe is not available.
It uses command.com without quotes, because command.com doesn't have this weird quote behavior.

Please try noclose.exe/noclose64.exe beta 2:
https://plugins.ghisler.com/addons/noclose_b2.zip
I think ideally quotes should be added and parameter /S should be used whenever possible in both cases
I agree. But here the problem is that I'm using COMSPEC, and parameter /C and not /K. So what I will do is check whether the command in COMSPEC is \cmd or \cmd.exe, and then use /S/K with quotes instead of /C without quotes.
Do you know of any other command interpreters I should check there? In my tests, /K doesn't work with powershell.exe, it requires /C.
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 6940
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: [TC 11.58rc1] Command line: quote added

Post by *white »

ghisler(Author) wrote: 2026-05-31, 09:45 UTC Please try noclose.exe/noclose64.exe beta 2:
https://plugins.ghisler.com/addons/noclose_b2.zip
Tested OK.
ghisler(Author) wrote: 2026-05-31, 09:45 UTC
I think ideally quotes should be added and parameter /S should be used whenever possible in both cases
I agree. But here the problem is that I'm using COMSPEC, and parameter /C and not /K. So what I will do is check whether the command in COMSPEC is \cmd or \cmd.exe, and then use /S/K with quotes instead of /C without quotes.
? It makes no difference whether /C or /K is used. /S is a modifier for both /C and /K.
ghisler(Author) wrote: 2026-05-31, 09:45 UTC Do you know of any other command interpreters I should check there? In my tests, /K doesn't work with powershell.exe, it requires /C.
I know of Take Command, which added support for /S in Take Command 24.02. The /S switch was already used for something, but they moved that function to the /B switch.
Take Command 24.02:
...
Changed the TCC /S startup switch to /B.
Added support for the CMD /S startup option to TCC.
(But they neglected to adjust the help text that is displayed when using TCC /?)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53138
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.58rc1] Command line: quote added

Post by *ghisler(Author) »

? It makes no difference whether /C or /K is used. /S is a modifier for both /C and /K.
/C and /K are not the same. cmd /C executes the command and closes, while cmd /K executes the command and stays open.
Powershell gives me an error when I pass /K to it.

For now I will use /S/K only for cmd.exe, and /C for all others as before.
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 6940
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: [TC 11.58rc1] Command line: quote added

Post by *white »

ghisler(Author) wrote: 2026-06-01, 07:51 UTC
? It makes no difference whether /C or /K is used. /S is a modifier for both /C and /K.
/C and /K are not the same. cmd /C executes the command and closes, while cmd /K executes the command and stays open.
I know. I meant that /S also works for /C. If you had /C before, why do you want to replace it with /S/K instead of /S/C ?

It would mean that you simply want to change the behavior from /C to /K, regardless of the parameter /S. I thought the distinction was on purpose:
* Enter on the command line -> console window closes after the command.
* Shift+Enter on the command line -> console window stays open.
You now want them to behave the same?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53138
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.58rc1] Command line: quote added

Post by *ghisler(Author) »

Yes, it should of course be /S/C, not /S/K. But Powershell doesn't seem to like /S/C either, it waits after opening until I press Enter before it executes the command.
Author of Total Commander
https://www.ghisler.com
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53138
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.58rc1] Command line: quote added

Post by *ghisler(Author) »

This has been fixed in RC2, please check!
Author of Total Commander
https://www.ghisler.com
User avatar
white
Power Member
Power Member
Posts: 6940
Joined: 2003-11-19, 08:16 UTC
Location: Netherlands

Re: [TC 11.58rc1] Command line: quote added

Post by *white »

ghisler(Author) wrote: 2026-06-09, 09:11 UTC This has been fixed in RC2, please check!
Tested OK as part of the other thread. I think this thread can be moved to fixed bugs.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 53138
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 11.58rc1] Command line: quote added

Post by *ghisler(Author) »

Thanks!

Moderator message from: ghisler(Author) » 2026-06-09, 13:19 UTC

Moved to fixed bugs
Author of Total Commander
https://www.ghisler.com
Post Reply