Page 1 of 1

Struggling with command-syntax...

Posted: 02 Mar 2016 11:45
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...?

Re: Struggling with command-syntax...

Posted: 02 Mar 2016 11:50
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...

Re: Struggling with command-syntax...

Posted: 02 Mar 2016 11:51
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:

Re: Struggling with command-syntax...

Posted: 02 Mar 2016 12:15
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 :-)

Re: Struggling with command-syntax...

Posted: 02 Mar 2016 13:06
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>"""

Re: Struggling with command-syntax...

Posted: 02 Mar 2016 14:26
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: )