quoting challenge

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
tiago
Posts: 583
Joined: 14 Feb 2011 21:41

quoting challenge

Post by tiago » 17 Aug 2011 02:17

I'm sure this is just a matter of right quoting I'm not going to make it work, so I'm asking a little help.

Code: Select all

run "c:\Programas\Sandboxie\start.exe" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>;
pops a warning on "system cannot locate the file".

Code: Select all

run ""c:\Programas\Sandboxie\start.exe" "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>";
almost does, opening windows explorer instead like in my first attempts to get a working formula for openwith menu.
Power-hungry user!!!

nas8e9
Posts: 1948
Joined: 21 Jun 2008 14:50

Re: quoting challenge

Post by nas8e9 » 17 Aug 2011 03:19

tiago wrote:I'm sure this is just a matter of right quoting I'm not going to make it work, so I'm asking a little help.

Code: Select all

run "c:\Programas\Sandboxie\start.exe" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>;
pops a warning on "system cannot locate the file".

Code: Select all

run ""c:\Programas\Sandboxie\start.exe" "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>";
almost does, opening windows explorer instead like in my first attempts to get a working formula for openwith menu.
Going by the help file, perhaps (I'm having some trouble testing this) something like this:

Code: Select all

run '"c:\Programas\Sandboxie\start.exe" "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL" <curitem>';
Note the single quotes around the double quotes plus the paramter. I'm basing the above on this help file snippet:
(2) Quoting items with blanks slightly differs:

run '"C:\With Blank.txt"'
Names with blanks must be quoted. Note that the quotes have to be wrapped in single-quotes because an argument's outer quotes are auto-stripped by XY's script parser!

run '"C:\Program Files\Winzip32.exe" -min'
Also wrapped in single-quotes because otherwise the "-" in "-min" would be interpreted as a math operater.
Should this not work, my first suspect would be the <curitem> parameter which may need to be within the double quotes for the RunDLL32.exe-command.

tiago
Posts: 583
Joined: 14 Feb 2011 21:41

Re: quoting challenge

Post by tiago » 17 Aug 2011 09:02

didn't worked single or doubled, thanks for trying.
Power-hungry user!!!

highend
Posts: 8104
Joined: 06 Feb 2011 00:33

Re: quoting challenge

Post by highend » 17 Aug 2011 09:14

I don't have sandboxie installed but what's wrong with:

Code: Select all

run """c:\Programas\Sandboxie\start.exe"" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL ""<curitem>""";
?
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

tiago
Posts: 583
Joined: 14 Feb 2011 21:41

Re: quoting challenge

Post by tiago » 17 Aug 2011 16:24

It doesn't open the list to choose a proper program from, opening the "windows cannot open this file" window instead.

The run "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>"; part does it right UN-sandboxed, of course, so the sum up is the reason why I believe it's just a matter of right quoting.
Power-hungry user!!!

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: quoting challenge

Post by TheQwerty » 17 Aug 2011 16:33

How about?

Code: Select all

run """c:\Programas\Sandboxie\start.exe"" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>";
EDIT: Note that I'm guessing here based on the fact that

Code: Select all

rundll32.exe shell32.dll,OpenAs_RunDLL "rundll32.exe"
Displays a cannot open this file "rundll32.exe" (with quotes) dialog. Where as:

Code: Select all

rundll32.exe shell32.dll,OpenAs_RunDLL rundll32.exe
Displays the open with dialog for rundll32.exe (without the quotes).

tiago
Posts: 583
Joined: 14 Feb 2011 21:41

Re: quoting challenge

Post by tiago » 17 Aug 2011 17:07

I'd really like to know what's going on with this, really...
IT WORKED, TheQwerty! :)

Thank you all guys! This will be far more useful than the initial "enqueue on winamp" query.
Power-hungry user!!!

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: quoting challenge

Post by TheQwerty » 17 Aug 2011 22:39

Just to provide some lessons to this thread and explain where other attempts went wrong...


Assuming <curitem> = D:\test.txt

Code: Select all

run "c:\Programas\Sandboxie\start.exe" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>;
Parsed & Resolved:
run
----
"c:\Programas\Sandboxie\start.exe" RunDLL32EXE SHELL32DLL
----
OpenAs_RunDLL D:\test.txt
The problem here is XY is attempting to guess where the first parameter of run ends. Outside of a quoted string the periods and comma signify concatenation and parameter delimiter respectively. Hence the resolved command removes the periods in RunDLL32.exe and Shell32.dll, and treats OpenAs... as your input for run's directory parameter.

Code: Select all

run ""c:\Programas\Sandboxie\start.exe" "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>";
Parsed & Resolved:
run
----
exe" "RunDLL32EXE SHELL32DLL
----
OpenAs_RunDLL D:\test.txt";
This one really throws XY for a loop. The "" at the start opens and closes a string. The C:\... isn't in the string, then the period in start.exe tells XY to concatenate strings, " " is another string, and RunDLL... is outside of the string. It's just terribly malformed, and as you'll notice stepping through it causes a number of overflow errors as XY tries to figure it out.

Code: Select all

run '"c:\Programas\Sandboxie\start.exe" "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL" <curitem>';
Parsed & Resolved:
run
----
"c:\Programas\Sandboxie\start.exe" "RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL" <curitem>
This one gets close but the use of single quotes '...' as the outer quotes means XY doesn't resolve any variables within the string. If start.exe can handle the passed parameters ("RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL" <curitem>) then it's going to be passing <curitem> literally to RunDLL/Shell32 instead of resolving it to D:\test.txt.

Code: Select all

run """c:\Programas\Sandboxie\start.exe"" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL ""<curitem>""";
Parsed & Resolved:
run
----
"c:\Programas\Sandboxie\start.exe" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL "D:\test.txt"
This is even closer but for whatever reason RunDLL32.exe doesn't handle the quotes around D:\test.txt like most other apps, for better or worse.

Code: Select all

run """c:\Programas\Sandboxie\start.exe"" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL <curitem>";
Parsed & Resolved:
run
----
"c:\Programas\Sandboxie\start.exe" RunDLL32.EXE SHELL32.DLL,OpenAs_RunDLL D:\test.txt
So why does this work? The outermost quotes tells XY this is the entire parameter, and since they are double quotes XY also parses and expands <curitem> to D:\test.txt. We must surround start.exe with quotes because we're also passing arguments to it, and double quotes are preferred (by Windows) so we need to escape them by doubling them up inside the string. start.exe and rundll32.exe seem to function just fine without their arguments being quoted so we don't bother adding more, but if they needed the arguments quoted we could surround them like we did start.exe.



So some notes to take away from this...
Double quotes ("string") tells XY to resolve any contained variables.
Single quotes ('string') tells XY NOT to resolve any contained variables.
To insert the outer quotes within your string double them up: "contains ""double"" quotes" / 'contains ''single'' quotes'.

It makes sense (and IMO is good practice) to always quote the parameters you provide to XY's scripting commands, as it helps both you and XY understand where each parameter starts and ends.

Run and similar commands typically want the first parameter to be a string containing: "app" arg1 argN
But depending on how app operates you may need to place the arguments in quotes as well: "app" "arg1" "argN".
So this means a run command will generally look like either:

Code: Select all

run """app"" arg1 argN";
run """app"" ""arg1"" ""argN""";
All these quotes can be a bit confusing at times so if you prefer you can use the quote scripting command:

Code: Select all

run quote("app" arg1 argN);
run quote("app" "arg1" "argN");
However remember that many common characters have special meaning in XY scripts when not contained in a string so...

Code: Select all

quote(a.b,c.d); //won't give you "a.b,c.d" but instead results in "ab".
quote(a;); //isn't even valid.
(Side-note: This is why I personally avoid Quote(). It gives a false sense of security and can do more harm than good.)


The best way to test your quoting is to enable stepping and view how XY interprets and parses your command (bottom of stepping window). However, this only helps you understand what XY is doing, and the app you wish to execute may have its own rules for how it handles arguments and needs quotes.


Lastly, don't be afraid to ask for help. Getting the quotes just right can be extremely confusing and frustrating, even when you feel you understand the rules well.

tiago
Posts: 583
Joined: 14 Feb 2011 21:41

Re: quoting challenge

Post by tiago » 18 Aug 2011 21:38

thank you very much for the clarifications, TheQwerty.
very appreciated!
Power-hungry user!!!

Post Reply