It is possible to run programs from Lisp by using the following function.
run-program runs program in a child process.
Program should be a pathname or string naming the program.
Args should be a list of strings which this passes to
program as normal Unix parameters. For no arguments, specify
nil. The value returned is either a process
nil. The process interface follows the description of
run-program fails to fork the child
process, it returns
Except for sharing file descriptors as explained in keyword argument
run-program closes all file descriptors in the
child process before running the program. When you are done using a
process-close to reclaim system resources. You
only need to do this when you supply
:stream for one of
:error, or you supply
nil. You can call
process-close regardless of whether
you must to reclaim resources without penalty if you feel safer.
run-program accepts the following keyword arguments:
This is an a-list mapping keywords and
simple-strings. The default is
:env is specified,
run-program uses the value given
and does not combine the environment passed to Lisp with the one
nil (the default), wait until the child
process terminates. If
nil, continue running Lisp while the
child process runs.
This should be one of
nil, or a stream. If
nil, the subprocess executes under a Unix PTY.
If specified as a stream, the system collects all output to this
pty and writes it to this stream. If specified as
process-pty slot contains a stream from which you can read
the program’s output and to which you can write input for the
program. The default is
This specifies how the program gets its input.
If specified as a string, it is the name of a file that contains
input for the child process.
run-program opens the file as
standard input. If specified as
nil (the default), then
standard input is the file /dev/null. If specified as
t, the program uses the current standard input. This may
cause some confusion if
nil since two processes
may use the terminal at the same time. If specified as
:stream, then the
process-input slot contains an
output stream. Anything written to this stream goes to the
program as input.
:input may also be an input stream that
already contains all the input for the process. In this case
run-program reads all the input from this stream before
returning, so this cannot be used to interact with the process.
:input is a string stream, it is up to the caller to call
string-encode or other function to convert the string to
the appropriate encoding. In either case, the least significant 8
bits of the
char-code of each
sent to the program.
This specifies what to do if
the input file does not exist. The following values are valid:
nil (the default) causes
run-program to return
without doing anything;
:create creates the named file; and
:error signals an error.
This specifies what happens with the program’s
output. If specified as a pathname, it is the name of a file that
contains output the program writes to its standard output. If
nil (the default), all output goes to
/dev/null. If specified as
t, the program writes to
the Lisp process’s standard output. This may cause confusion if
nil since two processes may write to the terminal
at the same time. If specified as
:stream, then the
process-output slot contains an input stream from which you
can read the program’s output.
:output can also be a stream
in which case all output from the process is written to this
:output is a string-stream, each octet read from
the program is converted to a character using
It is up to the caller to convert this using the appropriate
external format to create the desired encoded string.
This specifies what to do if the
output file already exists. The following values are valid:
run-program to return
nil without doing
:error (the default) signals an error;
:supersede overwrites the current file; and
appends all output to the file.
This is similar to
:output, except the file
becomes the program’s standard error. Additionally,
:output in which case the program’s error output is
routed to the same place specified for
:output. If specified
process-error contains a stream
similar to the
process-output slot when specifying the
This specifies what to do if the error
output file already exists. It accepts the same values as
This specifies a function to call whenever
the process changes status. This is especially useful when
nil. The function takes the process as
a required argument.
This specifies the external format to
use for streams created for
run-program. This does not
apply to string streams passed in as
If streams are created
use this as the
:element-type for the stream. Defaults to
|• Process Accessors|