Processes

Variable: home-directory

A string containing the home directory of the user.

Procedure: command-line

Returns a nonempty list of strings. The first element is an implementation-specific name for the running top-level program. (For now this is just "kawa", but it may become something more useful in the future.) The remaining elements are the command-line arguments, as passed to the main method.

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.

$ kawa -- abc=123 def
#|kawa:1|# (command-line)
(kawa abc=123 def)
#|kawa:2|# (process-command-line-assignments)
#|kawa:3|# (command-line)
(kawa 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: exit [code]

Exits the Kawa interpreter, and ends the Java session. The integer value code is returned to the operating system. If code is not specified, zero is returned, indicating normal (non-error) termination. If the code is #f, it is treated as -1, which means an abnormal exit.

Procedure: make-process command envp

Creates a <java.lang.Process> object, using the specified command and envp. The command is converted to an array of Java strings (that is an object that has type <java.lang.String[]>. It can be a Scheme vector or list (whose elements should be Java strings or Scheme strings); a Java array of Java strings; or a Scheme string. In the latter case, the command is converted using command-parse. The envp is process environment; it should be either a Java array of Java strings, or the special #!null value.

Procedure: system command

Runs the specified command, and waits for it to finish. Returns the return code from the command. The return code is an integer, where 0 conventionally means successful completion. The command can be any of the types handled by make-process.

Variable: command-parse

The value of this variable should be a one-argument procedure. It is used to convert a command from a Scheme string to a Java array of the constituent "words". The default binding, on Unix-like systems, returns a new command to invoke "/bin/sh" "-c" concatenated with the command string; on non-Unix-systems, it is bound to tokenize-string-to-string-array.

Procedure: tokenize-string-to-string-array command

Uses a java.util.StringTokenizer to parse the command string into an array of words. This splits the command using spaces to delimit words; there is no special processing for quotes or other special characters. (This is the same as what java.lang.Runtime.exec(String) does.)