1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: Operating System utilities
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Jul 2003
12 ;;;; *************************************************************************
16 (defun command-output (control-string &rest args)
17 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
18 synchronously execute the result using a Bourne-compatible shell,
19 returns (VALUES string-output error-output exit-status)"
20 (let ((command (apply #'format nil control-string args)))
22 (let* ((process (sb-ext:run-program
25 :input nil :output :stream :error :stream))
26 (output (read-stream-to-string (sb-impl::process-output process)))
27 (error (read-stream-to-string (sb-impl::process-error process))))
28 (close (sb-impl::process-output process))
29 (close (sb-impl::process-error process))
33 (sb-impl::process-exit-code process)))
37 (let* ((process (ext:run-program
40 :input nil :output :stream :error :stream))
41 (output (read-stream-to-string (ext::process-output process)))
42 (error (read-stream-to-string (ext::process-error process))))
43 (close (ext::process-output process))
44 (close (ext::process-error process))
49 (ext::process-exit-code process)))
52 (multiple-value-bind (output error status)
53 (excl.osi:command-output command :whole t)
54 (values output error status))
57 ;; BUG: Lispworks combines output and error streams
58 (let ((output (make-string-output-stream)))
61 (system:call-system-showing-output
64 :output-stream output)))
65 (values (get-output-stream-string output) nil status))
69 ;; BUG: CLisp doesn't allow output to user-specified stream
73 (ext:run-shell-command command :output :terminal :wait t))
76 (let* ((process (ccl:run-program
79 :input nil :output :stream :error :stream
81 (output (read-stream-to-string (ccl::external-process-output-stream process)))
82 (error (read-stream-to-string (ccl::external-process-error-stream process))))
83 (close (ccl::external-process-output-stream process))
84 (close (ccl::external-process-error-stream process))
87 (nth-value 1 (ccl::external-process-status process))))
89 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
90 (error "COMMAND-OUTPUT not implemented for this Lisp")
94 (defun run-shell-command (control-string &rest args)
95 "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
96 synchronously execute the result using a Bourne-compatible shell,
97 returns (VALUES output-string pid)"
98 (let ((command (apply #'format nil control-string args)))
100 (sb-impl::process-exit-code
104 :input nil :output nil))
107 (ext:process-exit-code
111 :input nil :output nil))
115 (excl:run-shell-command command :input nil :output nil
119 (system:call-system-showing-output
121 :shell-type "/bin/sh"
122 :output-stream output)
124 #+clisp ;XXX not exactly *verbose-out*, I know
125 (ext:run-shell-command command :output :terminal :wait t)
129 (ccl:external-process-status
130 (ccl:run-program "/bin/sh" (list "-c" command)
131 :input nil :output nil
134 #-(or openmcl clisp lispworks allegro scl cmu sbcl)
135 (error "RUN-SHELL-PROGRAM not implemented for this Lisp")