Testing std in/out/err. Closing port
This commit is contained in:
parent
c93dcdd374
commit
dbc53e840e
31
rash.rkt
31
rash.rkt
|
@ -1,16 +1,31 @@
|
|||
#lang racket/base
|
||||
|
||||
(require readline/readline)
|
||||
(require racket/string)
|
||||
|
||||
(define (do command . args)
|
||||
(let ([cmd (find-executable-path command)])
|
||||
(provide run)
|
||||
|
||||
(define (run command . args)
|
||||
(let ([cmd (find-executable-path command)]
|
||||
[output-port (file-port? (current-output-port))]
|
||||
[input-port (file-port? (current-input-port))]
|
||||
[error-port (file-port? (current-error-port))])
|
||||
(if cmd
|
||||
(let-values ([(subproc in out err)
|
||||
(subprocess (current-output-port)
|
||||
(current-input-port)
|
||||
(current-error-port)
|
||||
(subprocess output-port
|
||||
input-port
|
||||
error-port
|
||||
cmd
|
||||
(string-join args " "))])
|
||||
(subprocess-wait subproc))
|
||||
(raise (exn:fail:filesystem command)))))
|
||||
(subprocess-wait subproc)
|
||||
(when (input-port? in)
|
||||
(close-input-port in))
|
||||
(when (output-port? out)
|
||||
(close-output-port out))
|
||||
(when (output-port? err)
|
||||
(close-output-port err)))
|
||||
(raise (string-append command ": command not found")))))
|
||||
|
||||
(define (file-port? port)
|
||||
(if (file-stream-port? port)
|
||||
port
|
||||
#f))
|
||||
|
|
Loading…
Reference in New Issue
Block a user