589eac4b74e89a2ef798ce01030315a3770a87b9
[kmrcl.git] / os.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          os.lisp
6 ;;;; Purpose:       Operating System utilities
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Jul 2003
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; *************************************************************************
13
14 (in-package #:kmrcl)
15
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)))
21     #+sbcl
22     (sb-impl::process-exit-code
23      (sb-ext:run-program  
24       "/bin/sh"
25       (list  "-c" command)
26       :input nil :output nil))
27     
28     #+(or cmu scl)
29     (ext:process-exit-code
30      (ext:run-program  
31       "/bin/sh"
32       (list  "-c" command)
33       :input nil :output nil))
34     
35
36     #+allegro
37     (multiple-value-bind (output error status)
38         (excl.osi:command-output command)
39       (values output error status))
40     
41     #+lispworks
42     (system:call-system-showing-output
43      command
44      :shell-type "/bin/sh"
45      :output-stream output)
46     
47     #+clisp             ;XXX not exactly *verbose-out*, I know
48     (ext:run-shell-command  command :output :terminal :wait t)
49     
50     #+openmcl
51     (nth-value 1
52                (ccl:external-process-status
53                 (ccl:run-program "/bin/sh" (list "-c" command)
54                                  :input nil :output nil
55                                  :wait t)))
56            
57     #-(or openmcl clisp lispworks allegro scl cmu sbcl)
58     (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
59
60     ))
61
62 (defun run-shell-command (control-string &rest args)
63   "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
64 synchronously execute the result using a Bourne-compatible shell, 
65 returns (VALUES output-string pid)"
66   (let ((command (apply #'format nil control-string args)))
67     #+sbcl
68     (sb-impl::process-exit-code
69      (sb-ext:run-program  
70       "/bin/sh"
71       (list  "-c" command)
72       :input nil :output nil))
73     
74     #+(or cmu scl)
75     (ext:process-exit-code
76      (ext:run-program  
77       "/bin/sh"
78       (list  "-c" command)
79       :input nil :output nil))
80     
81     
82     #+allegro
83     (excl:run-shell-command command :input nil :output nil
84                             :wait t)
85
86     #+lispworks
87     (system:call-system-showing-output
88      command
89      :shell-type "/bin/sh"
90      :output-stream output)
91     
92     #+clisp             ;XXX not exactly *verbose-out*, I know
93     (ext:run-shell-command  command :output :terminal :wait t)
94     
95     #+openmcl
96     (nth-value 1
97                (ccl:external-process-status
98                 (ccl:run-program "/bin/sh" (list "-c" command)
99                                  :input nil :output nil
100                                  :wait t)))
101            
102     #-(or openmcl clisp lispworks allegro scl cmu sbcl)
103     (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
104
105     ))