Added contracts

This commit is contained in:
Cristian Esquivias 2014-08-12 21:41:26 -07:00
parent 27f80a1ccf
commit d539ba9d52

View File

@ -1,14 +1,25 @@
#lang racket/base
(require racket/contract)
(require racket/port)
(require racket/string)
(provide start pipe)
(define (executable? bin)
(find-executable-path bin))
(define (executable-list? command)
(and (find-executable-path (car command))
(foldl (λ (i j) (and i j)) #t (map string? (cdr command)))))
(provide (contract-out
[start (->* (executable? (listof string?))
(#:stdin (or/c #f file-stream-port?))
void?)]
[pipe (-> (listof string?) (listof string?)
void?)]))
(define (start command args #:stdin [stdin #f])
(define cmd (find-executable-path command))
(unless cmd
(raise (string-append command ": command not found")))
(define-values (proc out in err)
(apply subprocess
(current-output-port)