s c h e m a t i c s : c o o k b o o k

/ Cookbook.ProcessRunningExternalProcess

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

Running An External Process

Problem

You want to run an external program.

Solution

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.

> (require (lib "process.ss"))
> (system "touch ~/.login")
#t

Discussion

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):

> (require (lib "process.ss"))
> (system "ls -l *.ss")
#t

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:

> (require (lib "process.ss"))
> (system* "touch" "~/.login")
#f
> (system* "/bin/touch" "~/.login")
#f
> (system* "/bin/touch" "/home/pg/nhw/.login")
#t


Comments about this recipe

Contributors

-- NoelWelsh - 25 Feb 2005

CookbookForm
TopicType: Recipe
ParentTopic: ProcessRecipes
TopicOrder: 999

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest