r8931: command-output fixes
authorKevin M. Rosenberg <kevin@rosenberg.net>
Sun, 11 Apr 2004 01:36:14 +0000 (01:36 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Sun, 11 Apr 2004 01:36:14 +0000 (01:36 +0000)
io.lisp
os.lisp
package.lisp

diff --git a/io.lisp b/io.lisp
index d4c50ef6b28a5e93c960558ffc18fbbcf3b4fc55..6df15953c7b533c32a320a612c4b6481137a0a25 100644 (file)
--- a/io.lisp
+++ b/io.lisp
           (write-string line strm)
           (write-char #\newline strm))))))
 
+(defun read-stream-to-string (in)
+  (with-output-to-string (out)
+    (let ((eof (gensym)))                  
+      (do ((line (read-line in nil eof) 
+                (read-line in nil eof)))
+         ((eq line eof))
+       (format out "~A~%" line)))))
+       
 (defun read-file-to-string (file)
   "Opens a reads a file. Returns the contents as a single string"
   (with-output-to-string (out)
     (with-open-file (in file :direction :input)
-      (let ((eof (gensym)))                
-       (do ((line (read-line in nil eof) 
-                  (read-line in nil eof)))
-           ((eq line eof))
-         (format out "~A~%" line))))))
-
+      (read-stream-to-string in))))
+
+(defun read-stream-to-strings (in)
+  (let ((lines '())
+       (eof (gensym)))             
+    (do ((line (read-line in nil eof) 
+              (read-line in nil eof)))
+       ((eq line eof))
+      (push line lines)))
+  (nreverse lines))
+    
 (defun read-file-to-strings (file)
   "Opens a reads a file. Returns the contents as a list of strings"
-  (let ((lines '()))
-    (with-open-file (in file :direction :input)
-      (let ((eof (gensym)))                
-       (do ((line (read-line in nil eof) 
-                  (read-line in nil eof)))
-           ((eq line eof))
-         (push line lines)))
-      (nreverse lines))))
+  (with-open-file (in file :direction :input)
+    (read-stream-to-strings in)))
 
 (defun file-subst (old new file1 file2)
   (with-open-file (in file1 :direction :input)
diff --git a/os.lisp b/os.lisp
index 589eac4b74e89a2ef798ce01030315a3770a87b9..954a27f84796e1d277d29cd14319e60a92f01883 100644 (file)
--- a/os.lisp
+++ b/os.lisp
@@ -19,43 +19,65 @@ synchronously execute the result using a Bourne-compatible shell,
 returns (VALUES string-output error-output exit-status)"
   (let ((command (apply #'format nil control-string args)))
     #+sbcl
-    (sb-impl::process-exit-code
-     (sb-ext:run-program  
-      "/bin/sh"
-      (list  "-c" command)
-      :input nil :output nil))
+    (let ((process (sb-ext:run-program  
+                   "/bin/sh"
+                   (list "-c" command)
+                   :input nil :output :stream :error :stream)))
+      (values
+       (sb-impl::process-output process)
+       (sb-impl::process-error process)
+       (sb-impl::process-exit-code process)))
     
     #+(or cmu scl)
-    (ext:process-exit-code
-     (ext:run-program  
-      "/bin/sh"
-      (list  "-c" command)
-      :input nil :output nil))
-    
+    (let ((process (ext:run-program  
+                   "/bin/sh"
+                   (list "-c" command)
+                   :input nil :output :stream :error :stream)))
+      (values
+       (ext::process-output process)
+       (ext::process-error process)
+       (ext::process-exit-code process)))    
 
     #+allegro
     (multiple-value-bind (output error status)
-       (excl.osi:command-output command)
+       (excl.osi:command-output command :whole t)
       (values output error status))
     
     #+lispworks
-    (system:call-system-showing-output
-     command
-     :shell-type "/bin/sh"
-     :output-stream output)
+    ;; BUG: Lispworks combines output and error streams
+    (let ((output (make-output-string-stream)))
+      (unwind-protect
+         (let ((status 
+                (system:call-system-showing-output
+                 command
+                 :shell-type "/bin/sh"
+                 :output-stream output)))
+           (values (get-output-string output) nil status))
+       (close output)))
     
-    #+clisp            ;XXX not exactly *verbose-out*, I know
-    (ext:run-shell-command  command :output :terminal :wait t)
+    #+clisp            
+    ;; BUG: CLisp doesn't allow output to user-specified stream
+    (values
+     nil
+     nil
+     (ext:run-shell-command  command :output :terminal :wait t))
     
     #+openmcl
-    (nth-value 1
-              (ccl:external-process-status
-               (ccl:run-program "/bin/sh" (list "-c" command)
-                                :input nil :output nil
-                                :wait t)))
-          
+    (let* ((process (ccl:run-program  
+                    "/bin/sh"
+                    (list "-c" command)
+                    :input nil :output :stream :error :stream
+                    :wait t))
+          (output (read-stream-to-string (ccl::external-process-output-stream process)))
+          (error (read-stream-to-string (ccl::external-process-error-stream process))))
+      (close (ccl::external-process-output-stream process))
+      (close (ccl::external-process-error-stream process))
+      (values output
+             error
+             (nth-value 1 (ccl::external-process-status process))))
+  
     #-(or openmcl clisp lispworks allegro scl cmu sbcl)
-    (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
+    (error "COMMAND-OUTPUT not implemented for this Lisp")
 
     ))
 
index 9e61ef606fdfc5e93a3e23c41366dc544f3ae8d8..b04ab8e50f18c16a28ab0990d24ce7aa4e136801 100644 (file)
    
    ;; files.lisp
    #:print-file-contents
+   #:read-stream-to-string
    #:read-file-to-string
+   #:read-stream-to-strings
    #:read-file-to-strings
    
    ;; strings.lisp