Page 1 of 2
Quoting Hell - the never-ending story
Posted: 18 Aug 2015 00:13
by Stef123
This does not come easy to me, asking yet again for help with quoting.

But once again I can't figure it out. I use the exact same pattern you guys gave me last time, and yet - I can't believe it myself - it seems like it is different yet again.
I test a bunch of archives and then decide what to do with them, depending on the return codes. I spare you the details - here's the reduced code, I replaced all variables with real paths:
Code: Select all
foreach($item,<get selecteditemspathnames>,<crlf>) {
echo runret("""cmd"" /c ""D:\zip programs\7zip cmd\7za.exe"" t ""$item""");
};
What the heck is wrong with this line - why does echo return an empty box?
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 00:42
by highend
Em,... 7za.exe is already the command line version^^
Code: Select all
foreach($item,<get selecteditemspathnames>,<crlf>) {
echo runret("""D:\zip programs\7zip cmd\7za.exe"" t ""$item""");
}
why does echo return an empty box?
Because runret doesn't capture what 7za.exe would output into the dos box because of your quoting...
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 00:58
by Stef123
highend wrote:
Because runret doesn't capture what 7za.exe would output into the dos box.
Cannot confirm. I've been using 7za.exe for the past 3 weeks capturing its output, but now when I try it in XY for the first time, it fails me.
Besides:
This works: echo runret("""cmd"" /c D:\PogramFiles\7za.exe t ""<curitem>""");
I do get the correct readout when the path contains NO spaces. But I cannot avoid spaces in this case, this has got to be a quoting mistake once again. I think I have a fairly good understanding of the quoting procedures in XY by now, and this smells just like another case of quoting fire and brimstone.
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 01:06
by highend
Code: Select all
echo runret("""cmd"" /c """"D:\zip programs\7zip cmd\7za.exe"" t ""<curitem>""""");
Cool, right?
Use a step; in front of it too see how it's resolved...
But again, there is NO need to use a cmd call for a real command line utility. It makes quoting unnecessary complicated...
<- 2am, gotta sleep now
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 01:34
by Stef123
Too much food for thought - I am going insane with this stuff. What drives me up the wall - I can always get it to work as long the paths contain no spaces, but I cannot always avoid that.
Anyway, your example with the quintuple quotes works .... almost, thanks to step; I can see that the paths are passed correctly, except for the cmd which messes it all up. My main reason for using cmd /c is to avoid the screen flickering. I've found it the one reliable method to keep the screen quiet.
I better lay off and start using AHK for this stuff. I just thought that since by now I know fairly well what I am doing in ahk, it would be a good time to try replicate it in XY. Maybe not.

Need a break.
Thanks highend.

Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 13:15
by highend
Some commands just need an additional outer double quote if they are called from a different application.
E.g.: hstart (
http://www.ntwind.com/software/hstart.html) uses the same system.
From they samples section:
hstart.exe /NOUAC "notepad.exe "%SystemRoot%\System32\drivers\etc\hosts""
This isn't a problem of XY but any other application has to deal with such calls in the same way...
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 13:43
by Stef123
Yep. I do understand that part about the outer frame of quotes and all that. And also the necessity to put double quotes around paths with spaces.
But what I just don't get into my head - why ...
this here works:
Code: Select all
echo runret("""cmd"" /c D:\ProgramFiles\whatever.exe t ""$item""");
but this does not:
Code: Select all
echo runret("""cmd"" /c ""D:\Program Files\whatever.exe"" t ""$item""");
Irrespective of whether I need runret or not - just for educational practice lessons to get the hang of quoting. I am dumbfounded that I am
not able to pull off the very same thing just because a path contains spaces.
I understand it will cut off at the first blank and treat the remaining part as parameters, but holy shit, that's why I put the second term into double quotes, to take care of the blank, and yet it won't work.
Btw, interesting link, I am tempted to run some tests with it.
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 14:35
by Stef123
Eureka

- just by sheer might of force attacks - trying every possible combination possible:
This here works:
Code: Select all
echo runret("""cmd"" ""/c"" ""D:\Pogram Files\7za.exe"" ""t"" ""<curitem>""");
And once again I have to ditch all my quoting rules so diligently gathered and come up with the sobering realization that
There.Is.No.Rule.
There simply does not exist any rule that covers it all. Sometimes the parameters must not be quoted because it will mess up the command line, other times the only way to get it to work is to put ""quotes"" ""around"" ""every"" ""speck""
It's either trial and error, or plugging in some 3rd party tool - will try your hstart-link, thanks.
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 19:21
by highend
My main reason for using cmd /c is to avoid the screen flickering
What screen flickering? Can't see any difference between a runret() with cmd
and one without.
echo runret("""cmd"" ""/c"" ""D:\Pogram Files\7za.exe"" ""t"" ""<curitem>""");
It may work but it looks, em, terrible
Code: Select all
$command = <<<>>>
"cmd" /c ""D:\Pogram Files\7za.exe" t "<curitem>""
>>>;
echo runret($command);
Is at least a clean way to display it in a user friendly way, but I'd still prefer
Code: Select all
echo runret("""D:\Pogram Files\7za.exe"" t ""<curitem>""");
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 22:08
by Stef123
highend wrote:echo runret("""cmd"" ""/c"" ""D:\Pogram Files\7za.exe"" ""t"" ""<curitem>""");
It may work but it looks, em, terrible

granted, but I couldn't get it out of mind, had to figure it out. This has been haunting me, why would it work for non-space paths only? There's got to be a way to quote it for spaced paths as well, and afaict - this is the only way.
The example does not match my real problems.
The important point here is to have a repertoir of solutions that I can fall back on - out on the battlefield, at my clients' premises. Whatever they have - if I can run it from cmd, I
will be able to - might stand a chance - to get it to work from within XY as well. From network pinging to proprietary studio mixer macros.
Can't tell you why some programs will run silently without much fuss and flicker, while others jump and pop all over the place. But for some strange reason, they all behave nicely when using cmd /c
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 22:16
by highend
There's got to be a way to quote it for spaced paths as well, and afaict - this is the only way.
Code: Select all
echo runret("""cmd"" /c """"D:\zip programs\7zip cmd\7za.exe"" t ""<curitem>""""");
But I already posted that

Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 22:20
by Stef123
Yes you did, but your solution does not work

Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 22:42
by highend
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 22:51
by highend
And here the same, this time with 7z.exe in a path with spaces...
Code: Select all
echo runret("""cmd"" /c """"D:\Tools\7 Zip\7z.exe"" t ""<curitem>""""");
1.gif
Re: Quoting Hell - the never-ending story
Posted: 18 Aug 2015 22:53
by Stef123
Well, it was closer than my approach - that's why I said "almost" - but failed nevertheless. Will try later, I am on the wrong machine atm, cannot plug in my portable 7z ...
Maybe it's the path of the zipfile - without spaces in your screenshot - whatever it was, I will reproduce ... stay tuned....