Author Topic: Error loading a script from a process icon  (Read 3418 times)

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Error loading a script from a process icon
« on: 2013 March 31 14:25:08 »
I have detected a strange error running a script loading its parameters from a process icon. I have done the test in Win7 x64 and PI v1.8RC5.

The steps for reproducing the error are:
  • Open the attached script in the script editor and execute it.
  • Drag the "new instance" triangle to the workspace in order to create a new icon. This saves a parameter Param1="{\"A B\"}".
  • Close the dialog.
  • Select the icon and "Execute in the global context".
  • The script writes on the console the value of Param1. It should write Param1:{"A B"} but instead it writes Param1:{"A
This are the contents of the console log:
Code: [Select]
run -x -p="Param1,{"A B"}" --md5="bbb1d06da3054db95ceb53febb35d3f0" -p="isGlobalTarget,true" -p="isViewTarget,false" "C:/Users/Andres/Documents/PCL/test3.js"

Processing script file: C:/Program Files/PixInsight/B"}
File I/O Error: Unable to open file: Win32 error (123): El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos.: C:/Program Files/PixInsight/B"}

Processing script file: C:/Users/Andres/Documents/PCL/test3.js
Param1:{"A

If Param1 hasn't the space between A and B it works without error.

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Error loading a script from a process icon
« Reply #1 on: 2013 March 31 14:59:52 »
Hi Andrés,

This problem is due to a limitation of PI's command line interpreter. Instead of "A B", use 'A B', and it will work fine. In your test script, replace:

      var param1 = "{\"A B\"}";

with:

      var param1 = "{'A B'}";
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Error loading a script from a process icon
« Reply #2 on: 2013 March 31 15:09:49 »
The problem is that the string is generated by JSON.stringify and it uses ".

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Error loading a script from a process icon
« Reply #3 on: 2013 March 31 15:20:43 »
Then you'll have to replace all instances of double quote by single quote before setting each parameter value. Use something like:

foo.replace( /\"/g, "\'" )
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Andres.Pozo

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 927
Re: Error loading a script from a process icon
« Reply #4 on: 2013 April 01 01:25:52 »
As a temporal solution, this can work. However, there are more places where this is still a problem. For example, saving a parameter with a user defined string that includes a quotation mark. This is common case in the annotation script when the user wants to draw a label like ' Resolution 1.8 "/px '.

I can program around this, but it should not be necessary since PI escapes quotation marks in the parameters in other places as in the option "Edit Instance Source Code".

It is not urgent and it can wait (nobody has reported this problem yet), however I think that this would be better solved inside PI than in the script. Perhaps, instead writing each parameter in the command line it would be better to simply pass the name of the instance icon:
Code: [Select]
run -x -icon="Test3" -p="isGlobalTarget,true" -p="isViewTarget,false"
instead of
Code: [Select]
run -x -p="Param1,{"A B"}" --md5="bbb1d06da3054db95ceb53febb35d3f0" -p="isGlobalTarget,true" -p="isViewTarget,false" "C:/Users/Andres/Documents/PCL/test3.js"