A bug in TC's handling of parameters

The behaviour described in the bug report is either by design, or would be far too complex/time-consuming to be changed

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
JackFoo
Senior Member
Senior Member
Posts: 373
Joined: 2003-02-05, 19:53 UTC
Location: ERROR

A bug in TC's handling of parameters

Post by *JackFoo »

For some reason the original bur report was moved to "not going to be changed" however this is a real bug in TC:

see http://www.ghisler.ch/board/viewtopic.php?t=12859 for more info.

To clarify using %T without %M causes the same behaviour i.e. the target path gets quoted incorrectly.

Cheers.
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

I cannot confirm that. Process Explorer shows the correctly transfered command line, also when %M is empty (cursor located on [..].

Looks like your test.exe treats the backslash, which is added by %T, as a masking char for the following quotation mark...

Output of test.exe:

Code: Select all

c:\test\test.exe
/X:C:\Program Files\program\dummy.exe
/L:C:\WINDOWS\TEMP\CMDCD9.tmp
/F:c:\path with spaces" /N:2 /C:1024
Process Explorer:

Code: Select all

"c:\test\test.exe" /X:"C:\Program Files\program\dummy.exe" /L:C:\WINDOWS\TEMP\CMDCD9.tmp /F:"c:\path with spaces\" /N:2 /C:1024
Icfu
This account is for sale
User avatar
JackFoo
Senior Member
Senior Member
Posts: 373
Joined: 2003-02-05, 19:53 UTC
Location: ERROR

Post by *JackFoo »

Actually it's not my test.exe, it's the command interpreter of the console itself (command prompt) and since windows is probably not at fault it's how TC calls the process.

P.S. as you can see in the included code, test.exe does no manipulation of data in any way it simply reads the argv[], argv is filled by windows by following a specific set of commands, and is the standard.

P.P.S. But basically you're correct, the problem stems from the fact that TC ads \ to the category name but also quotes when needed, however \" is interpreted wrongly because it's an escape sequence which TC should render correctly - ie. \\" when needed.

Cheers.
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

It's not the console which interprets backslash as a masking char but it's C.

If TC would send \\", this would mean that all languages which do NOT use backslash as escape char would have to deal with the additional junk char.

Example, simple batch:

Code: Select all

Command: %comspec% /k
Parameter: output.cmd %T%M
output.cmd

Code: Select all

echo %1
Console output:

Code: Select all

"C:\path with spaces\\"
Icfu
This account is for sale
User avatar
JackFoo
Senior Member
Senior Member
Posts: 373
Joined: 2003-02-05, 19:53 UTC
Location: ERROR

Post by *JackFoo »

Actually that's not what happens when %M is not set, try setting the parameter as

Code: Select all

output.cmd %T
and you'll see what I mean.

What I get is C:\Program when the path should be C:\Program Files\...

Cheers.
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

2JackFoo
The quote problem seems to be the handling of the quotes in your short C program.
If I open cmd.exe and from there call your test program with parameter "C:\Path with spaces\",
it fails, too (without TC being involved):

Code: Select all

C:\Path with spaces>paramtest_c.exe "C:\Path with spaces\"
paramtest_c.exe
C:\Path with spaces"
While everything is OK using the batch version:

Code: Select all

C:\Path with spaces>paramtest.cmd "C:\Path with spaces\"
   %0: paramtest.cmd
   %1: "C:\Path with spaces\"
What I get is C:\Program when the path should be C:\Program Files\...
That is because TC only adds quotes, if both the directory and file name
are included in the expression (%T%M), not for %T alone.
That is to make strings possible like "%Tfile.ext" or "C:\%M" - quotes around %T or %M would disturb here.

:arrow: I couldn't find this info in the help (neither english or german) - did I overlook something :?:

So for %T the name gets splitted into 2 parameters:
  • %1 = C:\Program
    %2 = Files\
You can verify this and the correct behaviour in the above case
by changing the content of output.cmd to e.g. echo %* or

Code: Select all

echo %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
2icfu
It's not the console which interprets backslash as a masking char but it's C.
I'd basically agree - although it's quite weird, that the first backslash (\P) is treated as normal backslash, but the last one (\") as escape-sequence...
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

I'd basically agree - although it's quite weird, that the first backslash (\P) is treated as normal backslash, but the last one (\") as escape-sequence...
Here is more info about C command line parsing:
http://msdn2.microsoft.com/en-us/library/ms880421.aspx
A double quotation mark preceded by a backslash, \", is interpreted as a literal double quotation mark (").
Backslashes are interpreted literally, unless they immediately precede a double quotation mark.
Icfu
This account is for sale
User avatar
JackFoo
Senior Member
Senior Member
Posts: 373
Joined: 2003-02-05, 19:53 UTC
Location: ERROR

Post by *JackFoo »

Wel, C command line parsing is a defacto standard or even if not, most programs that you would call from the bar work this way. So IMHO something should be done to address it.

A solution can be simple, a checkbox to remove backslash at the end of a directory could suffice.

Cheers.
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

...or, to kill two birds with one stone, as requested for years already:
%O and %E equivalents for the target panel.

Icfu
This account is for sale
StatusQuo
Power Member
Power Member
Posts: 1524
Joined: 2007-01-17, 21:36 UTC
Location: Germany

Post by *StatusQuo »

2icfu
Here is more info about C command line parsing:
http://msdn2.microsoft.com/en-us/library/ms880421.aspx
Wow, a bug built in by design. :) Weird, but standard...
Thanks for the link.
Who the hell is General Failure, and why is he reading my disk?
-- TC starter menu: Fast yet descriptive command access!
Post Reply