Arg Functions in DIAL
The arg functions access arguments that are passed to the DIAL interpreter. The arguments are passed from the command line or the calling process, such as a DIAL process node in a Production script.
Returns the number of arguments that are passed to the DIAL script.
Returns the value of the specified argument that is passed to the DIAL script.
- If arg_num is 0, the function returns the file name of the DIAL script.
- If arg_num is 1, the function returns the first argument. For each succeeding increment of arg_num, the function returns the corresponding argument.
- If arg_num is greater than arg.count, the function returns a blank value.
For example, with an argument of "Steve":
console.writeln ("The program name was: \t" + arg.get(0));
console.writeln ("The first argument was: \t" + arg.get(1));
Returns the following:
The program name was: example_script.dial
The first argument was: Steve
Arg Function Examples
The following examples demonstrate the use of arg functions.
This script demonstrates the use of the arg function to access the arguments that are passed to the DIAL script.
console.writeln ("This script was called with \t" + arg.count() + "\t arguments.");
console.writeln ("The program name was: \t" + arg.get(0));
console.writeln ("The first argument was: \t" + arg.get(1));
console.writeln ("The second argument was: \t" + arg.get(2));
console.writeln ("The third argument was: \t" + arg.get(3));
The loop reads the arguments that are passed to the script. It sets the variable server to the string that follows the argument -server and the variable mode to the string that follows the argument -mode .
if(arg.count()>=2) {
argloop=1;
while(argloop<arg.count()) {
if(arg.get(argloop) == "-server") {
server=arg.get(argloop+1);
}
if(arg.get(argloop) == "-mode") {
mode=arg.get(argloop+1);
}
argloop=argloop+1;
}
}
console.writeln ("server: "+server);
console.writeln ("mode: "+mode);
The following example, when called with the string "hello world", assigns the text "hello world" to the variable welcome. If the quotation marks are not included to make the whole phrase a single string, only the text "hello" is assigned to arg(1). The text "world" is assigned to arg(2), even if not called.
diveline.connect("localhost","_Admin");
diveline.set_project("myProject");
welcome=arg.get(1);
console.writeln(welcome);
diveline.disconnect();
NOTE: If the script calls arguments that do not exist, the script continues silently without error.
Example 1 in Workbench
You cannot pass arguments when running DIAL scripts directly from the text editor in Workbench. You can, however, pass arguments to a DIAL script if you use Production. The Production DIAL node can define arguments that are passed to the script. For example:
After the script runs, click the DIAL node to view the results. For example, this image shows the Production script calling the DIAL script with arguments:
When you click the Click to View link on the DIAL script line item, you can see the messages that are sent to standard output. For example:
See also: DIAL Process Node.