Command_Line Package
The command_line package provides communication between a script and the
calling program. This package sets the exit status and processes command
line option switches. command_line contains following routines:
GCC Ada equivalent: Ada.Command_Line
s := command_line.argument( p )
|
Return a command line argument (the same as $n where n is a number). The arguments do not include option switches processed by SparForte. |
Example |
put_line( "First argument is " & command_line.argument( 1 ) ); |
Parameters |
Param |
Mode |
Type |
Default |
Description |
p |
in |
positive |
required |
the argument number |
s |
return value |
string |
required |
the value of the argument |
|
Exceptions |
A bad argument number will raise an exception. |
See Also |
- |
Compare With |
Ada: Ada.Command_Line.Argument PHP: argv |
n := command_line.argument_count
|
Return the number of script arguments (the same as $#). Excludes command line option switches processed by SParForte. |
Example |
if command_line.argument_count > 0 then ... |
Parameters |
Param |
Mode |
Type |
Default |
Description |
n |
return value |
natural |
required |
the argument count |
|
Exceptions |
- |
See Also |
- |
Compare With |
Ada: Ada.Command_Line.Argument_Count |
s := command_line.command_name
|
Return the path of the script or SparForte interpreter used to run the script (the same as $0). For example, in "/bin/spar myscript.sp" this will be
"/bin/spar". Or "/usr/local/myscript.sp foo" this will be "/usr/local/myscript.sp". |
Example |
put_line( command_line.command_name & " is this script"); |
Parameters |
Param |
Mode |
Type |
Default |
Description |
s |
return value |
string |
required |
the name of the script or SparForte interpreter |
|
Exceptions |
- |
See Also |
- |
Compare With |
Ada: Ada.Command_Line.Command_Name PHP: argv[0] |
n := command_line.environment.environment_count
|
Return the number of variables in the operating system environment. |
Example |
for i in 1..command_line.environment.environment_count loop -- loop through all environment variables |
Parameters |
Param |
Mode |
Type |
Default |
Description |
n |
return value |
natural |
required |
the argument count |
|
Exceptions |
- |
See Also |
- |
Compare With |
Ada: Ada.Command_Line.Environment.Environment_Count PHP: argc |
s := command_line.environment.environment_value( p )
|
Return an operating system environment value in the form of "VAR=value". |
Example |
put_line( "First value is " & command_line.environment.environment_value( 1 ) ); |
Parameters |
Param |
Mode |
Type |
Default |
Description |
p |
in |
positive |
required |
the variable number |
s |
return value |
universal_string |
required |
the value of the variable |
|
Exceptions |
A bad environment value number will raise an exception. |
See Also |
- |
Compare With |
Ada: Ada.Command_Line.Environment.Environment_Value PHP: $_ENV / getenv |
command_line.set_exit_status( n )
|
Set the status code to be returned by the script to the calling program. |
Example |
command_line.set_exit_status( 0 ); -- all is well |
Parameters |
Param |
Mode |
Type |
Default |
Description |
i |
in |
short_short_integer |
required |
the status code to return (0 for no error) |
|
Exceptions |
An exception is thrown if the value is out of range |
See Also |
os.status |
Compare With |
Ada: Ada.Command_Line.Set_Exit_Status |
|