How to get command-line arguments?

eridanibrew@gmail.com

Well-known member
OK, this is really stupid, but I can't figure it out.

I am looking to pass a command line argument to my script, for example to toggle a verbose logging flag. --help shows 2 possibilities, but I can't make either one work.

from help:

The run command loads and executes script files in the PixInsight JavaScript Runtime (PJSR) and core shell script engines.
Usage: run [<arg_list>] [<script_file_list>]

-a=<arg> | --argument=<arg>

Defines an argument that will be passed to the PJSR. Multiple instances
of this argument can be used to define an ordered list of script
arguments. The running script will have access to the list of arguments
through the jsArguments property of the Global JavaScript object.

-p=<id>,<value> | --parameter=<id>,<value>

Defines a parameter that will be passed to the PJSR. <id> and <value>
are the identifier and value, respectively, of a new script parameter.
If <id> has already been specified, its previous value is replaced.
Multiple instances of this argument can be used to define a list of
script parameters. The running script will have access to the passed
parameters with the get method of the Parameters core JavaScript
object. Note that for security reasons, script parameters are always
String objects. In this way, a script parameter cannot be used to
inject JavaScript code into PJSR.

Option 1
Tried to use a command line like
"C:\Program Files\PixInsight\bin\PixInsight.exe" -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js" --argument="verbose"
"C:\Program Files\PixInsight\bin\PixInsight.exe" -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js" -a=verbose
"C:\Program Files\PixInsight\bin\PixInsight.exe" --argument="verbose" -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js"
"C:\Program Files\PixInsight\bin\PixInsight.exe" -a="verbose" -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js"

Code:
for (var a in jsArguments)
{
console.writeln("argument is " + a);
}
This gives a popup message Unknown string argument: --argument=verbose.

Option 2
Used a command line like
"C:\Program Files\PixInsight\bin\PixInsight.exe" -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js" --parameter=verbose,true
"C:\Program Files\PixInsight\bin\PixInsight.exe" --parameter=verbose,true -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js"
"C:\Program Files\PixInsight\bin\PixInsight.exe" -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js" -p=verbose,true
"C:\Program Files\PixInsight\bin\PixInsight.exe" -p=verbose,true -n -r="D:\Dropbox\BrewSky\ACPHacks\PixInsight Scripts\Rotate\Flats\CalibFlatRotate.js"
...
Code:
var x = Parameters.get("verbose");
This gives a popup message Unknown string argument: --parameter=verbose,true.

After several hours of trying various combinations, this is apparently a truly difficult task. How can I pass some type of argument to my script?

Thanks,
brew
 
Hi Brew,
Can you not use a GUI interface and select an option that way?
Or is there a reason that you need to run it from the command line?
 
Last edited:
This is a script to do image calibration in an automated observatory. The calibration process is done without operator intervention. The script basically fills in the Gui fields and runs the processes Image Calibration, Cosmetic Correction, Image Integration, ...

For the moment I just want to pass in a verbose logging level switch. The script can generate a LOT of debugging information which I don't need to see when things are running well. I can see possibilities for other control parameters as well in the future.

I assume this would be a normal/possible thing to do, I just can't figure out how to do it. The "documentation" sounds like what I want although maybe I am reading it wrong.
 
I use Parameters but only in the context of Process Containers not from a command line............I was hoping that Juan would chip in on this one?
 
i was thinking that somewhere in the astrobin source on github there must be an example of the script interface to PI since they are now using PI to solve and annotate user images in the 'ultimate' tier. however it looks like astrobin is written in python and in a cursory look thru the code i only really saw a bunch of setup but no call. i probably just missed it, it might be worth taking a look.
 
Hi Brew,

Scripts executed through the command line upon application startup can be specified with an optional list or comma-separated arguments, which will be available as the global jsArguments array. For example, consider the following script:

JavaScript:
function printScriptArguments()
{
   for ( let i = 0; i < jsArguments.length; ++i )
      console.writeln( format( "%02d : ", i ), jsArguments[i] );
}

printScriptArguments();

Let's say that this script exists as the file "/path/to/foobar.js". A command-line invocation such as:

PixInsight -r="/path/to/foobar.js,0,100,b=true"

will cause the following script execution and console output:

Code:
run -a="0" -a="100" -a="b=true" --execute-mode=auto "/path/to/foobar.js"

Processing script file: /path/to/foobar.js
00 : 0
01 : 100
02 : b=true

Note that I have enclosed the value of the -r argument between double quotes. In general, this is always a good idea to prevent conflicts with characters or text fragments that could be interpreted in special ways by the running terminal.

Just for completeness, the Parameters core JavaScript object allows you to acquire parameters from a Script instance; for example when you run a script from an existing process icon. A script can be executed on a view (e.g. when you drop a Script process icon on an image) or as a global process. Parameters is useful in both contexts. For a good example of a very simple script using the Parameters object, see DrawSignature.

The run command loads and executes...

Please note that this information is valid for the run command, which is part of PixInsight's command-line interface. In other words, the run command can only be executed from PixInsight's Process Console. For complete information on command-line arguments of the PixInsight core application, run:

PixInsight --help

from a terminal. Or, if you use Windows:

C:\Program Files\PixInsight\bin\PixInsight.exe --help
 
Hi Rob,

i was thinking that somewhere in the astrobin source on github there must be an example of the script interface to PI since they are now using PI to solve and annotate user images in the 'ultimate' tier. however it looks like astrobin is written in python and in a cursory look thru the code i only really saw a bunch of setup but no call. i probably just missed it, it might be worth taking a look.

AstroBin is using a special 1.8.8-6 version of PixInsight with a custom process module that I have written (in C++) specifically to support the AstroBin+PixInsight collaboration project. This process calls the ImageSolver and AnnotateImage scripts, in a way similar to PhotometricColorCalibration. The process also implements a sophisticated network protocol and special SVG manipulation routines to generate annotations adapted to AstroBin website requirements. We'll probably released the source code of this module as open source under PCL license.

At least 4 concurrent instances of the PixInsight core application are permanently running on AstroBin's Amazon EC2 servers, and AstroBin communicates with them via special IPC commands.
 
Back
Top