command-line-argument-count

Function

Package: system

Arguments: &key application

This function and its relatives, command-line-arguments and command-line-argument, provide information about the command line that invoked Allegro CL. Their behavior depends on the value of the application keyword argument. If the value of that argument is true (the default is t), only the executable name and arguments appearing after the first occurrence of `--', if there is one, in the command line are considered. If the value of application is nil, all arguments, including the `--', if there is one, are included.

See Command line arguments in startup.htm for a list of command-line arguments accepted by Allegro CL.

command-line-argument returns the nth item on the command line. The item numbering is zero-based. If the value of the application keyword argument is true (the default), only the image name and the arguments after (and not including) the first occurrence of `--' in the command line are counted. If the value of application is nil, all arguments including the `--' are included. The executable name is argument 0. The argument is returned as a string.

command-line-arguments returns a list of strings indicating the arguments appearing on the command line used to start Allegro CL. If the value of the application keyword argument is true (the default), only the image name and the arguments appearing after the first occurrence of `--' are included. If the value of application is nil, all arguments including the `--', if there is one, are included.

command-line-argument-count returns the number of arguments on the Allegro CL command line. If the value of the application keyword argument is true (the default), only the image name and the arguments appearing after the first occurrence of `--', if there is one, are counted. If the value of application is nil, all arguments, including the `--', if there is one, are counted.

If the Allegro CL image was created with dumplisp (or build-lisp-image or generate-application) with the ignore-command-line-arguments argument true (the default is nil), then no argument is processed by Allegro CL when it starts up and all arguments (regardless of whether a `--' appears on the command line) are handled by these functions and the value of the application keyword argument has no effect.

The purpose of these functions is to allow you to customize the running of Lisp when the image is invoked. As a simple example, suppose you invoke Lisp (in this example, on Windows) as follows:

lisp.exe -qq -- foo -batch bar 

Here, lisp.exe is the name of the Allegro CL executable. No -I argument is specified so the image is lisp.dxl in the same directory as lisp.exe. Note first that Lisp will not run in batch mode since the -batch appears after `--'. However, no initialization file will be read since the -qq argument appears before the `--'.

Here is what the various command line functions return given that command line:

(sys:command-line-argument 0) 
[returns] "lisp.exe"
(sys:command-line-argument 1)
[returns] "foo"
(sys:command-line-argument 1 :application nil)
[returns] "-qq"
(sys:command-line-arguments)
[returns] ("lisp.exe""foo""-batch""bar")
(sys:command-line-arguments :application nil)
[returns] ("lisp.exe""-qq""--""foo""-batch""bar")
(sys:command-line-argument-count) 
[returns] 4
(sys:command-line-argument-count :application nil) 
[returns] 6

Note that the zeroth argument is the name of the executable as entered in the command line, with or without (in the example, without) path information. If you need the path of the executable,

(translate-logical-pathname (concatenate 'string "sys:"
(sys:command-line-argument 0)))

will typically work.

You may use this information as you see fit. One possible use, for example, is to have some function defined and run (perhaps in the initialization file .clinit.cl) which takes some action (such as loading specific files) based on the values of the arguments.

The documentation is described in introduction.htm and the index is in index.htm.

Copyright (c) 1998-2000, Franz Inc. Berkeley, CA., USA. All rights reserved.

Created 2000.10.5.