#lang scheme/base

(define-syntax pipe-between
  (syntax-rules (input:)
    ((_ (process args ...) rest ...)
     (pipe-between input: (current-output-port) (process args ...) rest ...))
    ((_ input: input (process args ...))
     (let-values
         (((pid stdout stdin error) (subprocess input
                                                (current-input-port) 
                                                (current-error-port) (find-executable-path process) args ...)))
       (subprocess-wait pid)))
    ((_ input: input (process args ...) rest ...)
     (let-values
         (((pid nothin stdin error) (subprocess (or input (current-output-port))
                                                 #f
                                                 (current-error-port) (find-executable-path process) args ...)))
       (pipe-between input: stdin rest ...)
       (close-output-port stdin)
       (subprocess-wait pid)))))

(define (main)
  (with-output-to-file
      "etc.cpio.gz"
    #:exists 'replace
   (λ ()
     (pipe-between
      ("gzip") ("cpio" "-o") ("find" "/etc" "-xdev")))))
(provide main)