process.ss: Process and Shell-Command Execution
To load: (require (lib "process.ss"))
This library builds on MzScheme's procedure; see
also section 15.2 in PLT MzScheme: Language Manual.subprocess
(system command-string) executes a Unix, Mac OS X, or Windows shell
command synchronously (i.e., the call to does not return until
the subprocess has ended). The systemcommand-string argument is a string
containing no null characters. If the command succeeds, the return value is
#t, #f otherwise.
(system* command-string arg-string ···) is like , except that
systemcommand-string is a filename that is executed directly (instead of
through a shell command), and the arg-strings are the arguments. The
executed file is passed the specified string arguments (which must contain no
null characters). Under Windows, the first arg-string can
be 'exact where the second arg-string is a complete command line;
see section 15.2 in PLT MzScheme: Language Manual for details.
(system/exit-code command-string) is like , except
that it returns the exit-code returned by the subprocess instead of a
boolean (a result of 0 indicates success).system
(system*/exit-code command-string) is like , except
that it returns the exit-code like system* does.system/exit-code
(process command-string) executes a shell command asynchronously. If the
subprocess is launched successfully, the result is a list of five values:
an input port piped from the subprocess's standard output,
an output port piped to the subprocess standard input,
the system process id of the subprocess,
an input port piped from the subprocess's standard error,9 and
a procedure of one argument, either
'status,'wait,'interrupt, or'kill:'statusreturns the status of the subprocess as one of'running,'done-ok, or'done-error.'exit-codereturns the integer exit code of the subprocess or#fif it is still running.'waitblocks execution in the current thread until the subprocess has completed.'interruptsends the subprocess an interrupt signal under Unix and Mac OS X, and takes no action under Windows. The result is void.'killterminates the subprocess and returns void.
Important: All three ports returned from must
be explicitly closed with process and
close-input-port.close-output-port
(process* command-string arg-string ···) is like , except
that processcommand-string is a filename that is executed directly, and the
arg-strings are the arguments. Under Windows, as for ,
the first system*arg-string can be 'exact.
(process/ports output-port input-port error-output-port
command-string) is like , except that processoutput-port
is used for the process's standard output, input-port is used
for the process's standard input, and error-output-port is used
for the process's standard error. The provided ports need not be
file-stream ports. Any of the ports can be #f, in which case a
system pipe is created and returned, as in . For each
port that is provided, no pipe is created and the corresponding
returned value is process#f.
(process*/ports output-port input-port error-output-port
command-string arg-string ···) is like , but with the port
handling of process*.process/ports
9 The standard error port is placed after the process
id for compatibility with other Scheme implementations. For the same
reason, returns a list instead of multiple values.process