System inquiry

Variable: home-directory

A string containing the home directory of the user.

Procedure: command-line

Returns a nonempty list of immutable strings. The first element is an implementation-specific name for the running top-level program. The remaining elements are the command-line arguments, as passed to the main method (except for those flags processed by Kawa itself).

The first element will depend on how the Kawa module was invoked. Kawa uses the following rules to determine the command name:

  1. If the property kawa.command.name is set, that is used. This variable can be set on the kawa command line, for example from a script:

    kawa -Dkawa.command.name="$0" foo "$@"
    

    This variable is also set implicitly by the meta-arg option. FIXME.

  2. If we’re reading a source file that starts with the Unix command-file prefix ‘#!/’ then we use the name of the source file. The assumption is that such a file is an executable script.

  3. If the Java property kawa.command.line is set, then we use that (after stripping off text that duplicates the remaining arguments). The kawa program sets this property to the command line used to invoke it (specifically the contents of the entire argv array), before invoking the java program.

  4. If the Java property sun.java.command is set, then we use that (after stripping off text that duplicates the remaining arguments), and then prepending the string "java ". The OpenJDK java program sets this property.

  5. If all else fails, the command name is "kawa".

Variable: command-line-arguments

Any command-line arguments (following flags processed by Kawa itself) are assigned to the global variable ‘command-line-arguments’, which is a vector of strings.

Procedure: process-command-line-assignments

Process any initial command-line options that set variables. These have the form name=value. Any such command-line options (at the start of the command-line) are processed and removed from the command-line.

$ java kawa.repl -- abc=123 def
#|kawa:1|# (write (command-line))
("java kawa.repl --" "abc=123" "def")
#|kawa:2|# (process-command-line-assignments)
#|kawa:3|# (write (command-line))
("java kawa.repl -- abc=123" "def")
#|kawa:4|# abc
123

This function is mostly useful for Kawa applications compiled with the --main option. (It is used to set XQuery external variables.)

Procedure: get-environment-variable name

Many operating systems provide each running process with an environment conisting of environment variables. (This environment is not to be confused with the Scheme environments that can be passed to eval.) Both the name and value of an environment variable are strings. The procedure get-environment-variable returns the value of the environment variable name, or #f if the environment variable is not found. (This uses the java.lang.System:getenv method.) It is an error to mutate the resulting string.

(get-environment-variable "PATH")
    ⇒ "/usr/local/bin:/usr/bin:/bin"

Procedure: get-environment-variables

Returns the names and values of all the environment variables as an alist, where the car of each entry is the name of an environment variable, and the cdr is its value, both as strings. It is an error to mutate any of the strings or the alist itself.

(get-environment-variables)
  ⇒ (("USER" . "root") ("HOME" . "/"))