Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The argv variable is a standard array field provided by the language to pass arguments into a script. It is predefined in all executions of the sil scripts

Where it is used

There may be situations where a single script is used in such a way that the argv variable is truly needed, so you may want to differentiate between calls:

Refer to each item documentation to see the parameters passed onto the argv variable

How to use it

Just like any other standard field, the argv variable can be called directly in any script. For example, the following script would print all the arguments in the argv variable in the log file.

Code Block
logPrint("INFO", argv);

Since the argv variable is an array it can also work with index operators:

Code Block
string firstArg = argv[0];
//or, provided that the invoking protocol defines a map array
string summaryValue = argv["summary"];

Or, since the argv variable is an array it can be iterated over using a loop:

Code Block
for(string argument in argv) {
    //do something with the value of the argument variable
}

Examples

SIL Runner Gadget Example

While it is usually better to use a parameter script to create input fields, generic parameters can be used and passed to the script.

image-20240213-195106.png

The values of the parameters can be accessed using the argv variable:

Code Block
runnerLog("I love to eat " + argv[0] + " and " + argv[1] + ".");
runnerLof("I don't like eating " + argv[2] + " unless they are over ripe.");

Call

routine

function example

This script is designed to be used by the call() routine function as reusable code. It is a function that derives the file name from the full file path.

getFileName.sil - reusable function

Code Block
string filePath = argv[0];
int start = lastIndexOf(filePath, "\\");
return trim(substring(filePath, start+1, length(filePath)));

Some other script

Code Block
call("", "Functions/getFileName.sil", "C:/Jira/someFile.txt")

SIL Scheduler example

For this example we have a scheduled script that will check the weather for several US ZIP codes and create new issues with the weather information.

image-20240213-193037.png

The following code excerpt shows how the arguments can be iterated over to perform the action for each ZIP code:

Code Block
...
for(string zipCode in argv) {
  weatherData wd = getForcast(zipCode);
  string newIssue = createIssue("WTHR", "", "Forcast", wd.summary);
  %newIssue%.description = wd.description;
  %newIssue%.temperature = wd.temp;
}
...

Contents:

Table of Contents
stylenone