Next Prev Up Top Contents Index

open-pipe

Function
Package

system

Syntax

open-pipe command &key { keyword value }* => stream

 

The valid keyword/value pairs are:

:direction {:input|:output|:io}

:element-type element-type

:interrupt-off {t|nil}

:shell-type

Arguments

command

A string

direction

A keyword. Either :input or :io .

element-type

A symbol.

interrupt-off

A boolean.

shell-type

A shell type.

Values

stream

A file stream.

Description

The behaviour of open-pipe is analogous to that of popen in the UNIX library. It creates a unidirectional pipe to/from a subprocess and returns a stream. The stream can be read from or written to as appropriate.

The command argument passes a shell command as a string.

direction is a keyword for the stream direction. The default value is :input . Bidirectional (i/o) pipes may be created by setting this keyword to :io . See the example below.

element-type specifies the type of the stream as with open . The default value is string-char .

interrupt-off , if t , ensures that Ctrl+C (SIGINT) to the LispWorks image is ignored by the subprocess.

shell-type specifies the type of UNIX shell to run.

Examples
CL-USER 1 > (setf *ls* (sys:open-pipe "ls"))
Warning: Setting unbound variable *LS*
#<SYSTEM::PIPE-STREAM "ls">
 
CL-USER 2 > (loop while
                  (print (read-line *ls* nil nil)))
 
"hello"
"othello"
NIL
NIL
 
CL-USER 3 > (close *ls*)
T

The following example shows you how to use bidirectional pipes.

CL-USER 1 >  (with-open-stream
                   (s (sys:open-pipe "/bin/csh"
                                     :direction :io))
                 (write-line "whereis ls" s)
                 (force-output s)
                 (read-line s))
"ls: /sbin/ls /usr/bin/ls /usr/share/man/man1.Z/ls.1"
NIL
See also

call-system
call-system-showing-output


LispWorks Reference Manual - 14 Dec 2001

Next Prev Up Top Contents Index