Page 1 of 1

Run fails to pass parameters with parenthesis

Posted: 03 May 2012 08:18
by Marco
XY 11.00.0001
XP HE SP3 ITA

Problem: the scripting command run fails to pass properly parameters containing parenthesis.
The following codes basically take an image via drag and drop to convert it in bmp. The final batch file can take two parameters, an image file path and a number ranging from 1 to 4. There's some smartness coded inside. These codes fail when the image contains parenthesis in the filename, i.e. the DOS window simply flashes on screen and no file output is produced. Spaces in filename don't cause the problem. I already debugged, as far as I can, the batch file and the XY scripts, and can't find code flaws explaining the behaviour. The bug supposed in the title is my best guess.

This script in the Catalog

Code: Select all

"1|<xypath>\..\Dexpot\Hintergrund Personalizzato 1.bmp"
 load "Desktop";
"2|<xypath>\..\Dexpot\Hintergrund Personalizzato 2.bmp"
 load "Desktop";
"3|<xypath>\..\Dexpot\Hintergrund Personalizzato 3.bmp"
 load "Desktop";
"4|<xypath>\..\Dexpot\Hintergrund Personalizzato 4.bmp"
 load "Desktop";
loads

Code: Select all

 $sfo=<get drop>;
 if ($sfo != "") {
  $sfo=quote($sfo);
 }
 $num=self("caption");
 run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;
The bat file itself is

Code: Select all

@echo off

color 5f

title %~n0

cd /d "%~dp0"

if not [%1]==[] (
	echo %1 | find /i ":\" > nul
	if not errorlevel 1 (
		set "sfo=%1"
	) else (
		set "num=%1"
	)
)

if not [%2]==[] (
	if defined sfo (
		set "num=%2"
	) else (
		set "sfo=%2"
	)
)

:sfondo

if not defined sfo set /p sfo="Sfondo del desktop: "

if exist %sfo% goto numero

set "sfo="
echo Sfondo inesistente.
echo Inserire uno sfondo valido nel prompt sottostante.
echo.

goto sfondo

:numero

if not defined num set /p num="Numero del desktop: "

if %num%==1 goto conversione
if %num%==2 goto conversione
if %num%==3 goto conversione
if %num%==4 goto conversione

set "num="
echo Numero non valido.
echo Inserire un numero valido nel prompt sottostante.
echo.

goto numero

:conversione

nconvert -overwrite -quiet -out bmp -o "..\Dexpot\Hintergrund Personalizzato %num%" %sfo%

Re: Run fails to pass parameters with parenthesis

Posted: 03 May 2012 16:35
by Marco
I tested placing the batch file in the Catalog and DnD'ing images on it: every image containing parenthesis triggered a flashing DOS window, and nothing more.
Running the .bat file normally is ok instead.

Re: Run fails to pass parameters with parenthesis

Posted: 03 May 2012 19:04
by admin

Code: Select all

run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;
Did you already try to quote $sfo?

Re: Run fails to pass parameters with parenthesis

Posted: 03 May 2012 19:55
by Marco
The script already takes care of that

Code: Select all

 if ($sfo != "") {
  $sfo=quote($sfo);
 }
(plus, I have no problems with filenames with spaces, the first symptom of missing quotes)

Re: Run fails to pass parameters with parenthesis

Posted: 03 May 2012 20:30
by admin
Can you send a screenshot of the Steps dialog when

Code: Select all

 run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;
is parsed with such a file.

Re: Run fails to pass parameters with parenthesis

Posted: 03 May 2012 22:38
by PeterH
admin wrote:Can you send a screenshot of the Steps dialog when

Code: Select all

 run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;
is parsed with such a file.
Just to ask: isn't there a level of quoting missing - or don't I understand documentation of the run command?

An example says:

Code: Select all

run '"C:\With Blank.txt"';
where we see outer single quotes to define the text "sent" to the run command, and inner double quotes surrounding the command inside the run command (to understand blanks).

And the above example contains blanks...

Re: Run fails to pass parameters with parenthesis

Posted: 03 May 2012 23:36
by Marco
Here it is, with a problematic file (notice the (8)). Then I tried an image named "Antwerp Central Station.jpg" (notice there are spaces) in the same folder and the script worked fine as I expect

PeterH: the script already works with the quotes I use, and adding the ' ' breaks it

Re: Run fails to pass parameters with parenthesis

Posted: 04 May 2012 00:30
by PeterH
Seems I was a bit asleep :roll:

I assume that XY run command doesn't have some "special handling", then:

- from view of the XY run command everything you specify is just one operand, i.e. the .bat and some parameters
- so it "should" follow XY rules for one operand - here a string.
- consisting of a constant string and variables it should be "somehow quoted"
- and parts of the string passed to run should be (double) quoted, too.

If I try to follow the XY rules (as I understand them), I'd construct either of:

Code: Select all

 run """<xypath>\..\CLI\NConvert - Desktop.bat"" $sfo $num";
 run '"<xypath>\..\CLI\NConvert - Desktop.bat"' . " $sfo $num";
Please note
- the doubled "double inner quotes" in the first example, where the variables just are inside the outer double quotes, prefixed by blanks
- the outer single quotes in the second example, where the parms-list is concatenated by dot,
- the double quotes for the variables in the 2nd example, where both variables are prefixed by a blank character.

As far as I interpret XY syntax, your (and Don's! :whistle: ) examples violate the rules of XY syntax, and can lead to any result - as far as XY run doesn't do any special handling of the string(s).

(Curious, what will be the result of this...)

Re: Run fails to pass parameters with parenthesis

Posted: 04 May 2012 12:04
by PeterH
Seems I still wasn't awake :oops:

My second example was nonsense: <variable> inside single quotes cannot work... :!:

Now I tested a bit.

1) created a .bat to simulate and verify:

Code: Select all

@Echo OFF
 Echo 1----

 Echo .%1
 Echo .%2
 Echo .%3

 Echo 2----
 
 Pause
2) created a "Try Script":

Code: Select all

 $sfo = "a (0)c";
 if ($sfo != "") {$sfo=quote($sfo);}
 $num = 123;

 run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;

 run """<xypath>\..\CLI\NConvert - Desktop.bat"" $sfo $num";
As far as I interpret the results they both seem correct!
(Though, for the first variant, I still think it's illegal syntax.)
(And by the way: interesting to comment the if ... quote(); statement)

And now :?:
Are you sure you interpret your results correct? I think you should add some debug (like my Echo statements) to your .bat and verify what happens.

Re: Run fails to pass parameters with parenthesis

Posted: 04 May 2012 21:20
by Marco
I have probably found the cause, the string echo "%1" | find /i ":\" > nul in the batch file.
I did some tests tho days ago, so this is unexpected to me.
Pardon Don :oops:

PeterH: thanks for the suggestions. Debugging with echo and pause is my way to operate. I probably overlooked something this time.
Regarding the if...quote: as I told, I wanted some smartness in the batch file, which is expected to work with zero, one or two parameters. The batch file, if launched from the Catalog, is run with at least one parameter for sure ($num=self("caption")).
Suppose now that I don't drop any image on i :then $num is really the only one parameter. If I wrote run "<xypath>\..\CLI\NConvert - Desktop.bat" "$sfo" $num, then the batch would perceive literally "" as the other parameter, and then would bother me with "" is not a valid image, please choose another file.

Re: Run fails to pass parameters with parenthesis

Posted: 04 May 2012 22:15
by PeterH
Glad that I could help to localize the problem...

@Don: could you please verify, that in the following the first statement isn't clean in syntax, with regard to quoting, while the second is? Else I would like to have some description about where I'm wrong, as I always try to exactly understand just these (basic) syntax rules. And I wouldn't love to tell people how to make it right, when I myself am possibly wrong...

Code: Select all

 run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;
 
 run """<xypath>\..\CLI\NConvert - Desktop.bat"" $sfo $num";

Re: Run fails to pass parameters with parenthesis

Posted: 04 May 2012 22:52
by Marco
Looks like I solved by removing the surrounding quotes in variable declaration, ending with

Code: Select all

if not [%1]==[] (
	echo %1 | find /i ":\" > nul
	if not errorlevel 1 (
		set sfo=%1
	) else (
		set num=%1
	)
)

if not [%2]==[] (
	if defined sfo (
		set num=%2
	) else (
		set sfo=%2
	)
)
Btw, parenthesis seems to be known to cause some parsing problems in DOS (after reading somewhere on tech forums).

Re: Run fails to pass parameters with parenthesis

Posted: 05 May 2012 10:49
by admin
PeterH wrote:Glad that I could help to localize the problem...

@Don: could you please verify, that in the following the first statement isn't clean in syntax, with regard to quoting, while the second is? Else I would like to have some description about where I'm wrong, as I always try to exactly understand just these (basic) syntax rules. And I wouldn't love to tell people how to make it right, when I myself am possibly wrong...

Code: Select all

 run "<xypath>\..\CLI\NConvert - Desktop.bat" $sfo $num;
 
 run """<xypath>\..\CLI\NConvert - Desktop.bat"" $sfo $num";
You are/were right.

Re: Run fails to pass parameters with parenthesis

Posted: 05 May 2012 11:31
by PeterH
Thanks!