The library process.ss in MzLib? provides handy utilities for both synchronous and asynchronous communication with processes. This recipe covers the simpler synchronous communication style.
The following example code runs the Unix touch command to update the timestamp on a file.
%begin scheme%
> (require (lib "process.ss"))
> (system "touch ~/.login")
#t
%end%
Note that system only indicates success or failure of running the specified program. To capture the output on the program see ProcessCaptureOutput.
The system function runs its commands via a shell, so program names are resolved using the current setting of the PATH environment variable (or its equivalent) and other shell features such as wildcards can be used. The following example shows the use of shell wildcards (although as the output is thrown away the example serves now purpose):
%begin scheme%
> (require (lib "process.ss"))
> (system "ls -l *.ss")
#t
%end%
There is a variant on system called system* that takes multiple arguments. The first argument is the name of the program, and the remaining arguments are passed as arguments to the process. However system* does not run its command via a shell, so you must give the full path to the program and cannot use shell features. For example the touch example must be rewritten:
%begin scheme%
> (require (lib "process.ss"))
> (system* "touch" "~/.login")
#f
> (system* "/bin/touch" "~/.login")
#f
> (system* "/bin/touch" "/home/pg/nhw/.login")
#t
%end%