system.rkt
#lang racket/base

(require racket/port)

(define in-null #f)

(define out-null #f)

(define (good-port p)
   (if (file-stream-port? p)
     p
     (if (input-port? p)
       (begin
         (when (not in-null) (set! in-null (open-input-file "/dev/null")))
         in-null)
       (begin
         (when (not out-null)
           (set! out-null (open-output-file #:exists 'append "/dev/null")))
         out-null))))

(define (new-system command . args)
   (let-values (((pid foo bar blech)
                 (apply
                  subprocess
                  (good-port (current-output-port))
                  (good-port (current-input-port))
                  (good-port (current-error-port))
                  command
                  args)))
     (sync/enable-break pid)
     (= 0 (subprocess-status pid))))

(define (schlorp command . args)
   (let-values (((pid input bar blech)
                 (apply
                  subprocess
                  #f
                  (good-port (current-input-port))
                  (good-port (current-error-port))
                  command
                  args)))
     (begin0 (port->bytes input) (sync/enable-break pid))))

(provide (rename-out (new-system system*)) schlorp good-port)