button bar command quotes not right

Please report only one bug per message!

Moderators: sheep, Hacker, Stefan2, white

Post Reply
ppp
Junior Member
Junior Member
Posts: 6
Joined: 2012-02-09, 03:19 UTC

button bar command quotes not right

Post by *ppp »

using commands in button bar, is broken on long filename dirs..
when i use a batch file for command that's in a long filename dir, it doesn't work..[with %P%S for params]
to make it work correctly, i have to put a single double-quote in front of the command: "c:\path to\command.bat
and put closing double-quote in my params: " %P%S
so the command eventually gets to be "c:\path to\command.bat" %P%S when put back together...
otherwise, even echoing out the params with:
for %%1 in (%*) do echo %%1
doesn't work...
so something's knocking off the ending quote from command at top..
[ps i tried using no quotes and still not work when having long filename paths.

User avatar
MVV
Power Member
Power Member
Posts: 8502
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Every parameter with spaces must be enclosed with quotes (a pair of quotes, one before and one after parameter, not just single quote). In your example:
1st parameter: "c:\path to\command.bat" - a pair of quotes;
2nd etc parameters: %P%S - TC quotes paths with spaces.
So I can't see any problem here.

ppp
Junior Member
Junior Member
Posts: 6
Joined: 2012-02-09, 03:19 UTC

Post by *ppp »

ahh, but that's just it, if you put 2 quotes on command, it doesn't work..
it's only by putting one up top, and one in params does it work...
hence the bug...
i should be able to put a leading and trailing quote on the command, and none in params line, but it knocks off the trailing one on the command for some reason..so only option is to put it on params line to get it to work properly..

ppp
Junior Member
Junior Member
Posts: 6
Joined: 2012-02-09, 03:19 UTC

broken in previous versions as well

Post by *ppp »

i see it's broken in 7.50 as well... :(

same behavior as mentioned before, 2 quotes on command that needs them don't work, the second quote gets stripped off for some reason..

as i said before, putting 2 quotes on command and none on params line doesn't work..
i have to add a quote on params line because the second one on command line gets chopped off at runtime..

cmd: "command
param: " %P%S
works..

cmd: "command"
param: %P%S
doesn't..:(

User avatar
MVV
Power Member
Power Member
Posts: 8502
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

A-h, I understood reason of your problem. I forget about it last time. Batch files are executed by cmd.exe which works in stupid way in XP:

Code: Select all

cmd.exe /c "command parameters"

Code: Select all

cmd.exe /c ""c:\path to\command.bat" "1.txt" "2.txt" "3.txt""
It requires additional pair of quotes around command and parameters, and it cuts ending quote if first command symbol is quote.

Anyway it is not a TC problem, TC simply tells Windows to execute batch file, and system starts cmd.exe with corrsesponding parameters.

So I recommend to use direct command if you need to start batch file:

Code: Select all

Command: cmd.exe /c ""c:\path to\command.bat"
Parameters: %P%S "
Don't forget last quote, cmd.exe will cut it from last quoted parameter otherwise.

ppp
Junior Member
Junior Member
Posts: 6
Joined: 2012-02-09, 03:19 UTC

Post by *ppp »

so it looks as if the problem is the quotes around the "command parameters"...who puts those in? they aren't needed at all..
each command/param will have it's own quotes if needed so that extra set surrounding it all is completely unnecessary..
cmd.exe doesn't require it..
try running cmd.exe /c "some command" param1 param2
or cmd.exe /c command param1 param2
no problem..

so wherever the 'extra' set of quotes are coming from is messing the whole thing up..

so why does my workaround of putting second quote on second line work?
the second quote isn't getting 'removed', it's made obsolete by closing itself before the data it's supposed to be quoting:

cmd.exe /c ""c:\path to\command.bat" "1.txt" "2.txt" "3.txt""
equals
cmd.exe /c empty quoted string-"", unquoted path-c:\path to\command.bat, another empty quote-" ", unquoted-1.txt,empty quote-" ",etc,etc...

see what i'm saying?
the extra surrounding quotes make all starting quotes into ending quotes, and vice-versa..

User avatar
MVV
Power Member
Power Member
Posts: 8502
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Yes, they aren't needed for human. But it is Microsoft...

Try to open command line and execute following command:

Code: Select all

cmd.exe /c ""c:\path to\command.bat" "1.txt" "2.txt" "3.txt""
It works fine.

And then try to remove first and last quotes...

Code: Select all

cmd.exe /c "c:\path to\command.bat" "1.txt" "2.txt" "3.txt"
It doesn't work! It says that it can't find a file "c:\path". As I said, it removes first and last characters if they are both quotes (and does nothing if not).

You can check command line that you get by your way (from 1st post), it produces following one:

Code: Select all

cmd /c ""c:\path to\command.bat " C:\1.txt"
I don't know why it works but it works. Stupid cmd.exe's logic (or maybe OS just cuts spaces at the end of filename when cmd opens the file).

ppp
Junior Member
Junior Member
Posts: 6
Joined: 2012-02-09, 03:19 UTC

Post by *ppp »

ahh,i see now...only with quotes on params does it mess up...
why using cmd /c?
shellexecutes don't have this problem..[at least i think..lol]

it's just that this is confusing to the user, going against conventional standards and logic..but i understand now it's win's fault..still..

sorry to take up your time on this but it seems a messy way for this otherwise perfect program to have to deal with this simple problem that's apparently been around for ages..

does this not affect regular executables? [.exe]

User avatar
MVV
Power Member
Power Member
Posts: 8502
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

ShellExecute for BAT files executes cmd.exe /c. :D
Batch files are not executables so require special command processor.

In case of regular application only that application controls parameter processing.

ppp
Junior Member
Junior Member
Posts: 6
Joined: 2012-02-09, 03:19 UTC

Post by *ppp »

well thanx for spreading some light on it..i get around this in for loops by making it @"command" which works fine..
[so first char isn't quote]
TC doesn't let me use that but you might be able to code it in if it does work inside program as well..:)
[just thought it might be a workaround]

Post Reply