• Aucun résultat trouvé

Operating-system interface

Dans le document 4400 SERIES COMMON LISP (Page 48-54)

A note on portability

4 Operating-system interface

4.1 Subprocess functions 4-1 4.2 Environment functions 4-3 4.3 Image functions 4-4

11-86)

4 Operating-system interface

This chapter describes functions in Tek COMMON LISP that interact with the host operating system. These functions include those providing control and interaction with subprocesses, determination and change of the current working directory, and saving the state of a LISP session.

system :os-wait [Function]

• If a process is started by the excl:run-shell-command with :wait being nil), then the process will remain in the system until either LISP exits or the process exits and LISp executes system:os-wait to inquire about the exit status. To prevent the system becoming clogged with processes, a program that spawns a number of processes with :wait set to nil must be sure to call system:os-wait for each spawned process. This function returns two values, the exit status of the process, and the process identification number. If there are no subprocesses running, then it will return immediately with the values nil, nil.

excl:run-shell-command command &key :input :output :error-output :wait :if-input-does-not-exist :if-output-exists :if-error-output-exists

[Function]

• This function returns either one or three values, depending on the value of :waif. If :wait is t, the single value returned is the exit status of the spawned process. If :wait is nil, the three values returned are

stream-a stream-b process-id

where stream-a is a stream if either :input or :output is :stream and nil otherwise; and stream-b is a stream if :error-output is :stream and nil otherwise. The process-id is the spawned process's process identification number. Thus the user can communicate with the spawned process, including running any shell command, easily communicating the output to LISP. Writing to stream-a will send input to the spawned process if :input is :stream, and reading from stream-a will read the output of the process if :output is :stream.

4.1

Subprocess

functions

4-1

Tektronix, Inc.

4-2 Operating-system interface

o

The values of :input, :output, and :error-output control what the pro-cess will use as standard input (file descriptor 0), standard output (file descriptor 1) and standard error (file descriptor 2). The values can be

• nil-inherit standard input, output or error (respectively) from Lisp.

~ This is UNIX standard input and output inherited from the LiSp

process and is unrelated to the LISP variables *standard-input* and

*standard-output* .

• A pathname (or string )--open the file specifed by the pathname (or string) and use the stream;

• A stream-use the stream (which must be able to do input/output in the right direction);

• :stream--create create a stream and return it to the LiSp program.

Since waiting and having a stream open to a process can cause the process to hang, :wait must be nil; if :wait is t, an error will result.

:error-output has an additional allowed value: :output, which directs standard error to the same place as standard output. The default value in all cases is nil.

o

:wait may be t or nil. If :wait is t, LiSp will wait for the command to exit before resuming. If :wait is nil, LiSp will start the process and then resume without waiting for it to finish. The default for :wait is t.

o

The keywords :if-input-does-not-exist, :if-output-exists and :if-error-output-exists all are used for better control when :input, :output or :error-output are pathnames (or strings), LISP uses open to open a stream to the file identified by the pathname (or string) and the values of :if-input-does-not-exist, :if-output-exisfs and :if-error-output-exists are passed to the open function as the value of the :if-does-not-exist parameter (for :input) or the :if-exists parameter (for :output or :error-output.) The permissable values for :if-does-not-exist are :error, :create and nil and for :if-output-exists and :if-error-output-exists are :error, :0 verwrite , :append, :supersede and nil. The default is :error in all cases.

Here are examples of excl:run-shell-command. The first runs a simple shell command (path). The output goes to standard output (in this case the terminal.)

<cl> (run-she11-command "path") /usr/tech/dm

cox ttyp2 Sep 15 17:19

dm ttyp8 Sep 16 14 :01 (franz)

o

<cl>

The next example reads the output into a stream, which can be manipulated by

LiSp.

D.<Jt-02(26-1

Tek COMMON LISP Operating-system interface 4-3

<cl> (run-sheIl-command "csh" :input :stream : output : stream :wait nil)

*<buffered terminal stream @ *x2c8c39>

nil 12059

<cl> (setq foo *)

*<buffered terminal stream @ *x2c8c39>

<cl> (format foo "path -%")

;; -% is a carriage return nil

<cl> foo

*<buffered terminal stream @ *x2c8c39>

<cl> (read fool /usr/tech/dm

excl :shell &opfional command [Function}

• If the command argument is not given, then an interactive shell is spawned. To get back to LISP, exit from the shelL If the command (a string) is given, then a shell is spawned and directed to execute that com-mand.

excl:chdir pathname &key simple [Function}

• This function changes the current directory of the process to the direc-tory denoted by pathname (using the name and type information, not just the directory component of the pathname), and then sets the *defauft-pathname-defaufts* to the directory just changed to. Argument simple defaults to nil, but if it is set to t, then *defauft-pathname-defaults* is unchanged (allowing, for example, files to be easily loaded from the origi-nal directory.) invoked Tek COMMON LiSp. They return, respectively, a string naming the nth argument (or the program name, if n is 0); a list of strings naming the program and the arguments; and a [unum equal to the number of

4.2

Environment functions

Tektronix, Inc.

4-4 Operating-system interface

4.3

Image functions

arguments.

excl :username-to-home-directory name [Function]

• Return a pathname with the directory component holding the named user's home directory. returns nil if the name is not recognized by the sys-tem.

system :getenv string [Function]

• This function returns the value (a string) of an environment variable (such as "TERM"). If the environment variable is not defined, nil is returned.

excl:dumplisp &key :name :restart-function :read-init-file [Function]

• Save an image of the currently executing COMMON LISP as an execut-able file. The name of the executexecut-able file will be savedcl unless the :name argument is provided. Unless the :read-init-file argument is given a value nil, when the saved image is executed, it will will search for and load the .clinit.cl file (see chapter 5, Top level, for a description of this file). Normally, the next step is for the top level to print a prompt and enter the read-eval-print loop. If however the :restart-function argument is given a non-nil value, then that value will be funcalled. Should the :restart-function return, the standard read-eval-print loop will be entered.

excl :exit &optional val [Function]

• Exit LISP and return exit status val to the operating system or shell.

0·01-02126-11

·'6)

Dans le document 4400 SERIES COMMON LISP (Page 48-54)

Documents relatifs