Struggling with command-syntax...

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Struggling with command-syntax...

Post by MBaas »

Despite RTFM'ing, I'm not getting it :((
I'm struggling with the correct format to set up a command to run on a user-button. when the name of the executable contains spaces.

For example, I have a file "patch (Classic).exe" in <xyscripts> that I'd like to call.
So I've setup the script as:

Code: Select all

"Patch (Classic)" run '"<xyscripts>\patch (Classic).exe"'

which looks quite right according to the doc of the "run"-command. Also when I paste just <xyscripts>\patch (Classic).exe into the commandline, it executes fine.
But when I trigger the user-command I get an error:
Das System kann die angegebene Datei nicht finden.

File: "<xyscripts>\patch (Classic).exe"

Parameters:
run
"<xyscripts>\patch (Classic).exe"
When replacing the blank with _, it works nicely. But I'd like to understand what I'm doing wrong...?
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

highend
Posts: 14994
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Struggling with command-syntax...

Post by highend »

Putting something in single quotes -> Variables are not resolved inside of it!
Das System kann die angegebene Datei nicht finden.

File: "<xyscripts>\patch (Classic).exe"
It's already there: <xyscripts> -> Not resolved into the correct path...
One of my scripts helped you out? Please donate via Paypal

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Struggling with command-syntax...

Post by PeterH »

For outer single quotes everything inside is used exact as it is specified. (Also <xyscripts>!)
So you must use double outer quotes.
But that means: double quotes inside double quotes must be doubled :ugeek:

So:

Code: Select all

 "Patch (Classic)" run """<xyscripts>\patch (Classic).exe"""
(assuming everything else was correct :whistle: )

edit: highend was faster :mrgreen:

MBaas
Posts: 692
Joined: 15 Feb 2016 21:08

Re: Struggling with command-syntax...

Post by MBaas »

I had seen that the vars were not resolved, so I also had tried double-quoting, but triple-quoting somehow just did not come to mind. Thanks guys, works nicely now :-)
____________________________________________________________________________________
Happy user. Screen scaling 100% and W11Pro [Version 10.0.26200.7922], XY 28.30.14000 * * LinkTree

binocular222
Posts: 1424
Joined: 04 Nov 2008 05:35
Location: Win11, Win10, 100% Scaling

Re: Struggling with command-syntax...

Post by binocular222 »

The rule is: the run command should look like this:
run "XX"
Where XX is a path. If XX contain space, then it should be double-quoted like this:
""<path>""

Combining the 2 above, we have triple quote:
run """<path>"""
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Struggling with command-syntax...

Post by PeterH »

binocular222 wrote:The rule is: the run command should look like this:
run "XX"
Where XX is a path. If XX contain space, then it should be double-quoted like this:
""<path>""

Combining the 2 above, we have triple quote:
run """<path>"""
I'd say: this isn't really correct! To understand: try to use "basic" rules.

The operand of the XY-run-cmd is a string. This string contains a Windows-Command, and optionally parameters for that command. Both are blank-separated, so Windows :!: cannot distinguish a blank inside the command from blanks to separate multiple parameters. To help Windows you must deliver the command quoted:
"<xyscripts>\patch (Classic).exe"

Let me build this, in a basic way, using XY syntax:

Code: Select all

 $wincmd = '"' . <xyscripts> . '\patch (Classic).exe' . '"';
 run $wincmd;
You see: I specified all strings in *single* quotes - so that included variable names would *not* be resolved, and double quotes can simply be included. (If there were single quotes inside, *these* would have to be doubled.) The 3 dots concatenate the 4 strings to one.
Here you *might* combine the last 2 strings to one: '\patch (Classic).exe"' -> both are identical.


With all outer *double* quotes the same(!) would be (note the doubled double-quotes):

Code: Select all

 $wincmd = """" . <xyscripts> . "\patch (Classic).exe" . """";
 run $wincmd;
As a variable (here: <xyscripts>) is resolved inside *double* quotes, now all strings can be combined into one:

Code: Select all

 $wincmd = """<xyscripts>\patch (Classic).exe""";
 run $wincmd;
This, again, is identical to the previous expression.

So:
- to specify a string in XY: use single or double quotes (saying to XY: this is a string)
- if a string for windows contains a filename etc, it must be surrounded by double quotes, *if* it maybe contains blanks. (For XY these quotes are part of a string!)
- if a string in XY contains double quotes, and is inside double quotes, the contained double quotes must be doubled.


As a result I think the use of strings containing variables, all specified inside double quotes, prevents unexperienced users from learning how you have to specify strings, and why it is this way.
(Though I wouldn't want to miss the ability to code it this way :roll: )

Post Reply