Run fails to pass parameters with parenthesis

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Run fails to pass parameters with parenthesis

Post 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%
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Run fails to pass parameters with parenthesis

Post 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.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Run fails to pass parameters with parenthesis

Post by admin »

Code: Select all

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

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Run fails to pass parameters with parenthesis

Post 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)
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Run fails to pass parameters with parenthesis

Post 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.

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

Re: Run fails to pass parameters with parenthesis

Post 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...

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Run fails to pass parameters with parenthesis

Post 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
To see the attached files, you need to log into the forum.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

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

Re: Run fails to pass parameters with parenthesis

Post 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...)

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

Re: Run fails to pass parameters with parenthesis

Post 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.

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Run fails to pass parameters with parenthesis

Post 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.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

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

Re: Run fails to pass parameters with parenthesis

Post 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";

Marco
Posts: 2354
Joined: 27 Jun 2011 15:20

Re: Run fails to pass parameters with parenthesis

Post 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).
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

admin
Site Admin
Posts: 67337
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Run fails to pass parameters with parenthesis

Post 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.

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

Re: Run fails to pass parameters with parenthesis

Post by PeterH »

Thanks!

Post Reply