Usercmd.ini path quotes

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
zsero
Junior Member
Junior Member
Posts: 27
Joined: 2007-02-01, 15:03 UTC

Usercmd.ini path quotes

Post by *zsero »

The quoting of paths behaves very strange when used inside usercmd.ini

Here is how %P works:
1. When used inside cmd= part => not substituted, called as "%P"
2. param=%P => not quoted
3. param="%P" => still not quoted
4. param=""%P" => correctly quoted

I believe the correct functionality should be a simple %P which is quoted when path contains spaces.

What I see is that you have to hack 2 quotes before %P and 1 quote after to make it work somehow.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

zsero,
You should keep in mind that INI files have their own quoting rules. Some parameters (with quotes, outer spaces or whatever else, don't know exactly) must be enclosed into outer quotes.

So in your case (3) INI parser simply removes these outer quotes leaving parameter w/o them.

If you don't know how to quote INI parameter, let TC do it, and it will read same strings that it stores.
E.g. when I use "%P" in TC user-command editor (cm_CommandBrowser), it stores ""%P"" into usercmd.ini, just as I said above: exact parameter string plus outer quotes.
zsero
Junior Member
Junior Member
Posts: 27
Joined: 2007-02-01, 15:03 UTC

Post by *zsero »

OK, I had a look at using that editor and there are even more bugs:

1.

Code: Select all

%P
in the editor window becomes

Code: Select all

param=%P
in the ini file.

The sent command is like

Code: Select all

"program" long path
Total Commander does not quote paths containing space this way! I believe this is a bug!

2.

Code: Select all

"%P"
in the editor window becomes

Code: Select all

param=""%P""
. This is what you were referring as .ini style quoting.
Total Commander calls the program like

Code: Select all

"program" "long path""
<- broken " on the right side

Buggy as well, as the constructed long path is not quoted properly, the given path does not exists.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50923
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Windows itself removes quotes from ini entries when they are read, but only when it begins AND ends with quote.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

zsero wrote:Total Commander does not quote paths containing space this way! I believe this is a bug!
TC doesn't promise to quote paths that are got using %P parameter, only for %P%N, so it is better to quote explicitly.
zsero wrote:<- broken " on the right side
Tested it just a minute ago. I've created command em_test with command cmd.exe and parameter "%P", in usercmd.ini I see param=""%P"".
Then I've executed em_test from TC command line and checked process command line using Process Hacker, it was "C:\Windows\System32\cmd.exe" "C:\Program Files (x86)", just as expected.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50923
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Indeed TC only quotes %P%N and %T%M (and a few others) where it is certain that quoting is needed. Since these variables can be used in many many combinations, TC cannot know when quoting is necessary and when not. Just put quotes yourself.
Author of Total Commander
https://www.ghisler.com
zsero
Junior Member
Junior Member
Posts: 27
Joined: 2007-02-01, 15:03 UTC

Post by *zsero »

OK, %P should be quoted then, that part is not a bug.

But "%P" in GUI => ""%P"" in .ini file still results in a bug.

I have to remove one " at the end to make it work.

Here is a Python script to test it, but I'm sure you can write one in any single language:

Code: Select all

from sys import argv

print argv

raw_input()


I'm using 8.0.1 32-bit in Win 7 64-bit.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

But "%P" in GUI => ""%P"" in .ini file still results in a bug.
It is not a bug, it is a Windows API function behaviour, and I wrote that it works fine for me, so API correctly reads written string from file. Please use not Python command line parser but task manager like Process Explorer to validate low-level command line.

I think problem may be in backslash that TC writes at the end of path, just before quote: some stupid programs treat "\"" in parameters like '"' character, so this may cause such strange things in your Python if it also does so.
zsero
Junior Member
Junior Member
Posts: 27
Joined: 2007-02-01, 15:03 UTC

Post by *zsero »

And how can I check the real called argument in Process Explorer? Does it have some kind of logging functionality? I couldn't find it.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You need to start something that will not close immediately, and while it is running, you can open process properties in Process Explorer or Process Hacker and check command line.
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

You can also set the "Difference Highlighting Duration" to 9 secs (under options). Any closed process is highlighted red. Just right-click it and select Properites to show the command line.
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

ZoSTeR,
Nice feature, haven't noticed it before. However it can't show anything useful for terminated processes, command line field is empty and all other fields are empty, N/A or zeroes.
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

MVV,
Here the whole line in the process list stays filled with the same info even while the process is closing and the line is in red.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
zsero
Junior Member
Junior Member
Posts: 27
Joined: 2007-02-01, 15:03 UTC

Post by *zsero »

Aaaah, I got it!

1. setting the command to cmd.exe it's very easy to diagnose the full command in Process Explore, as you have said.

With this, I can conclude that:
1. some processes, like cmd.exe need

Code: Select all

param=""%P""
2. some other processes, like python or cmder.exe, use "\" as an escape character, thus the trailing path\" becomes an additional ". This way, I have to manually remove this one by editing the .ini file, and changing it to

Code: Select all

param=""%P"
Solution

Is to use "%P\" as parameter, thus it would end at \\, thus double-escaping \.

p.s.: feel free to move this out of bug topics, there is nothing buggy in TC
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

[mod]Moved to the English forum.

Hacker (Moderator)[/mod]
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
Post Reply