Cannot use quotes in command button parameters

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
rduke15
Junior Member
Junior Member
Posts: 10
Joined: 2005-05-15, 22:10 UTC

Cannot use quotes in command button parameters

Post by *rduke15 »

Hello,

Just came across a problem with command buttons and quotes. I have a batch file which I want to call from a button like this:

Code: Select all

mybatch.bat "%P" > "%P\outfile.txt"
(where Total Commander replaces %P with the pathname).

If I put this whole command in the "Command" box, the %P Total Commander variable is not expanded but used litterally instead, and my batch file sees the first argument as "%P".

So I put

Code: Select all

mybatch.bat
into "Command" and

Code: Select all

"%P" > "%P\outfile.txt"
into Parameters. But then the start quote is removed by Total Commander. The result is that the path is invalid.

For example, if my current dir is "C:\My Path", my batch file sees the first argument as "C:\My" and the second as "Path"" (with a trailing quote).

I tried various combinations of quotes, but found no way of giving a correctly quoted path argument to my batch file.
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

1. %P already includes the trailing backslash so you should change %P\outfile.txt to %Poutfile.txt
2. Besides that it should work flawlessly, I have no problems with your example.

I suppose that the error is in your batch.

Have you checked the transferred arguments with Process Explorer or something like that? Just add a pause at the end of your script, then you have enough time to check it.

Also you can try this batch instead:
echo %1
echo %2
echo %3

Will tell you if the parameters are "really" wrong.

Icfu
This account is for sale
User avatar
nsp
Power Member
Power Member
Posts: 1805
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Cannot use quotes in command button parameters

Post by *nsp »

rduke15 wrote:Hello,

So I put

Code: Select all

mybatch.bat
into "Command" and

Code: Select all

"%P" > "%P\outfile.txt"
into Parameters. But then the start quote is removed by Total Commander. The result is that the path is invalid.

For example, if my current dir is "C:\My Path", my batch file sees the first argument as "C:\My" and the second as "Path"" (with a trailing quote).

I tried various combinations of quotes, but found no way of giving a correctly quoted path argument to my batch file.
Hi RDuke15,

As ICFU, I got the right stuff in my bat file if i do like you. But after some modification, i've seen that the first and the last " can be eaten if i have a space before or after the last quote.
you can try to add a ? in front of you parameters string to verify that you have the right stuff in it.


B) if you want to have a better handling for bat file, you can just use TCBL http://www.ghisler.ch/board/viewtopic.php?t=9374&highlight=tcbl ;)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

%something parameters are not handled in the command field, only in the parameters field. Why? They could collide with %env% environment variable strings in the command field.

You may try to enclose the entire parameter in additional "" to preserve them.
Author of Total Commander
https://www.ghisler.com
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

They could collide with %env% environment variable strings in the command field.
In the parameters field it's vice versa...

Code: Select all

Command: notepad.exe
Parameter: %Programfiles%\blabla\blubb.txt
Result: Path not found

You could get rid of this limitation by offering a (user-defined) char alias for %. This would make it possible to enable env and internal vars in both fields.

Icfu
This account is for sale
User avatar
Clo
Moderator
Moderator
Posts: 5731
Joined: 2003-12-02, 19:01 UTC
Location: Bordeaux, France
Contact:

Good !

Post by *Clo »

2icfu

:) Hello Jeff !
You could get rid of this limitation by offering a (user-defined) char alias for %. …
• It sounds like a very good idea, I support it !
- Then, we could have i.e. :
†variable_blah_blah†
If I got you alright… ?

:mrgreen: VG
Claude
Clo
#31505 Traducteur Français de TC French translator Aide en Français Tutoriels Français English Tutorials
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Nope, instead of %P you write †P. The env var char % mustn't be changed.

Edit: Yeah, I got it I think. R.I.P., dear proposal? ;)

Icfu
This account is for sale
User avatar
Clo
Moderator
Moderator
Posts: 5731
Joined: 2003-12-02, 19:01 UTC
Location: Bordeaux, France
Contact:

Maybe…

Post by *Clo »

2icfu
Edit: Yeah, I got it I think. R.I.P., dear proposal? ;)
:D Maybe something like this…

• Seriously, since you request an ALIAS for "%", any chosen stated character might do the trick, might it not ?
- So, why not † or ‡ (for Russian friends users) ?

:mrgreen: VG
Claude
Clo
#31505 Traducteur Français de TC French translator Aide en Français Tutoriels Français English Tutorials
icfu
Power Member
Power Member
Posts: 6052
Joined: 2003-09-10, 18:33 UTC

Post by *icfu »

Yes, any character will do it. But only as a replacement for % in TC internal variables %P, %N, etc...
†variable_blah_blah†
looks like you want to replace the % in env vars like %program files% which is not a good idea probably. Of course, it could also be done but it would complicate things for ghisler, that's why I said "Nope".

So, I would propose the following:
If the user has defined an alias, use % only for env vars.
If the user has not defined an alias, everything stays compatible to the present behaviour.

Icfu
This account is for sale
User avatar
Clo
Moderator
Moderator
Posts: 5731
Joined: 2003-12-02, 19:01 UTC
Location: Bordeaux, France
Contact:

For the fun…

Post by *Clo »

2icfu

:) Good proposal, I support it !
If the user has not defined an alias, everything stays compatible to the present behaviour.
… and its hiccups :P

:mrgreen: VG
Claude
Clo
#31505 Traducteur Français de TC French translator Aide en Français Tutoriels Français English Tutorials
User avatar
XPEHOPE3KA
Power Member
Power Member
Posts: 854
Joined: 2006-03-03, 18:23 UTC
Location: Saint-Petersburg, Russia

Post by *XPEHOPE3KA »

- So, why not † or ‡ (for Russian friends users) ?
OMFG, what do you mean, Clo?
F6, Enter, Tab, F6, Enter, Tab, F6, Enter, Tab... - I like to move IT, move IT!..
User avatar
Clo
Moderator
Moderator
Posts: 5731
Joined: 2003-12-02, 19:01 UTC
Location: Bordeaux, France
Contact:

For each religion…

Post by *Clo »

2XPEHOPE3KA

:) Hello !

• No offence anyway, I just showed the corresponding character … ;)

:mrgreen: FR
Claude
Clo
{ Please, check your mail…}
#31505 Traducteur Français de TC French translator Aide en Français Tutoriels Français English Tutorials
rduke15
Junior Member
Junior Member
Posts: 10
Joined: 2005-05-15, 22:10 UTC

SOLVED

Post by *rduke15 »

After many tests, this problem is finally soved. Indeed, it actually worked as expected with plain windows batch files.

But my batch file was really a wrapper around a Perl script. And the argument sent to it was a path, so it was ending with a backslash. The backslash was "escaping" the closing quote!

In other words, when I put [face=courier]"%P"[/face] in Parameters, my batch would receive the correct and quoted [face=courier]"C:\Some Path\"[/face], which it would hand over to Perl. Perl would then remove the surrounding quotes, except that the closing quote was "escaped" because of the backslash. Finally, my parameter ended up being [face=courier]C:\Some Path"[/face] in my script.

The solution was to remove the trailing quote in the perl script with a simple [face=courier]s/"$//;[/face]

Thanks to all who looked into this.
Post Reply