Usercmd.ini path quotes
Moderators: Hacker, petermad, Stefan2, white
Usercmd.ini path quotes
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.
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.
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.
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.
OK, I had a look at using that editor and there are even more bugs:
1. in the editor window becomes in the ini file.
The sent command is like
Total Commander does not quote paths containing space this way! I believe this is a bug!
2. in the editor window becomes . This is what you were referring as .ini style quoting.
Total Commander calls the program like <- broken " on the right side
Buggy as well, as the constructed long path is not quoted properly, the given path does not exists.
1.
Code: Select all
%P
Code: Select all
param=%P
The sent command is like
Code: Select all
"program" long path
2.
Code: Select all
"%P"
Code: Select all
param=""%P""
Total Commander calls the program like
Code: Select all
"program" "long path""
Buggy as well, as the constructed long path is not quoted properly, the given path does not exists.
- ghisler(Author)
- Site Admin
- Posts: 50923
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
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
https://www.ghisler.com
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:Total Commander does not quote paths containing space this way! I believe this is a bug!
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"".zsero wrote:<- broken " on the right side
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.
- ghisler(Author)
- Site Admin
- Posts: 50923
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
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
https://www.ghisler.com
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:
I'm using 8.0.1 32-bit in Win 7 64-bit.
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.
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.But "%P" in GUI => ""%P"" in .ini file still results in a bug.
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.
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
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
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
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""
Code: Select all
param=""%P"
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