[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

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 := argument( p ) - return argument p
  n := argument_count - number of arguments
  s := command_name - number of  environment vars
  n := environment.environment_count - number of variables in the O/S environment 
  s := environment.environment_value( p ) - return environment value p
  set_exit_status( n ) - change script exit status code
 
Help Command: Contents of the command_line package

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

 
[Right Submenu]

 Summary

 arrays

 btree_io

 calendar

 cgi

 chains

 command_line

 db/ postgresql

 dbm

 directory_operations

 doubly_linked...

 dynamic_hash_...

 enums

 exceptions

 files

 gnat.cgi

 gnat.crc32

 hash_io

 lock_files

 memcache

 memcache.highread

 mysql

 mysqlm

 numerics

 os

 pen

 pen (OpenGL)

 records

 sound

 source_info

 stats

 strings

 System

 teams

 templates

 text_io

 units

[Back to Top] Back To Top [Small Forte Symbol]