CommandParm PowerScript function
Description
Retrieves the argument string, if any, that followed the program
name when the application was executed.
Syntax
|
1 |
<span>CommandParm </span>( ) |
Return Values
String. Returns the application’s
argument string if it succeeds and the empty string (“”) if it fails
or if there were no arguments.
Usage
Command arguments can follow the program name in the command
line of a Windows program item or in the Program Manager’s
Run response window. For example, when the user chooses File>Run
in the Program Manager and enters:
|
1 |
MyAppl C:EMPLOYEEEMPLIST.TXT |
CommandParm retrieves the string C:EMPLOYEEEMPLIST.TXT.
If the application’s command line includes several
arguments, CommandParm returns them all as a
single string. You can use string functions, such as Mid and Pos,
to parse the string.
You do not need to call CommandParm in
the application’s Open event. Use the commandline argument
instead.
Examples
These statements retrieve the command line arguments
and save them in the variable ls_command_line:
|
1 |
string ls_command_line |
|
1 |
ls_command_line = <span>CommandParm</span>() |
If the command line holds several arguments, you
can use string functions to separate the arguments. This example
stores a variable number of arguments, obtained with CommandParm,
in an array. The code assumes each argument is separated by one
space. For each argument, the Pos function searches
for a space; the Left function copies the argument
to the array; and Replace removes the argument
from the original string so the next argument moves to the first position:
|
1 |
string ls_cmd, ls_arg[] |
|
1 |
integer i, li_argcnt |
|
1 |
|
1 |
// Get the arguments and strip blanks |
|
1 |
// from start and end of string |
|
1 |
ls_cmd = Trim(<span>CommandParm</span>()) |
|
1 |
|
1 |
li_argcnt = 1 |
|
1 |
DO WHILE Len(ls_cmd) > 0 |
|
1 |
// Find the first blank |
|
1 |
i = Pos( ls_cmd, " ") |
|
1 |
|
1 |
// If no blanks (only one argument), |
|
1 |
// set i to point to the hypothetical character |
|
1 |
// after the end of the string |
|
1 |
if i = 0 then i = Len(ls_cmd) + 1 |
|
1 |
|
1 |
// Assign the arg to the argument array. |
|
1 |
// Number of chars copied is one less than the |
|
1 |
// position of the space found with Pos |
|
1 |
ls_arg[li_argcnt] = Left(ls_cmd, i - 1) |
|
1 |
|
1 |
// Increment the argument count for the next loop |
|
1 |
li_argcnt = li_argcnt + 1 |
|
1 |
|
1 |
// Remove the argument from the string |
|
1 |
// so the next argument becomes first |
|
1 |
ls_cmd = Replace(ls_cmd, 1, i, "") |
|
1 |
LOOP |