Ticket #496: shell-escaping.patch

File shell-escaping.patch, 1.5 KB (added by Moritz Heidkamp, 13 years ago)
  • shell.scm

     
    11;;;; shell.scm
    22
    33
    4 (module shell (execute run run* shell shell shell-verbose command)
     4(module shell (execute run run* shell shell-verbose)
    55
    66(import scheme chicken)
    7 (use extras utils data-structures)
     7(use data-structures posix)
    88
    99
    1010(define shell-verbose (make-parameter #f))
    1111
    12 (define (command . cmds)
    13   (apply
    14    values
    15    (map (lambda (cmd)
    16           (string-intersperse (map ->string (flatten cmd))))
    17         cmds)))
    18 
    1912(define (execute cmds #!key status verbose)
    2013  (let ((ss
    2114         (map
    2215          (lambda (cmd)
    23             (let ((cmd (command cmd)))
    24               (when (or verbose (shell-verbose))
    25                 (printf "  ~A~%~!" cmd))
    26               (let ((r (system cmd)))
    27                 (cond (status r)
    28                       ((not (zero? r))
    29                        (error
    30                         'execute
    31                         "shell command failed with non-zero exit status"
    32                         cmd r))))))
     16            (let ((cmd (flatten cmd)))
     17              (when (or verbose (shell-verbose))
     18                (printf "  ~A~%~!" (string-intersperse cmd)))
     19              (let ((r (nth-value 2 (process-wait (process-run (car cmd) (cdr cmd))))))
     20                (cond (status r)
     21                      ((not (zero? r))
     22                       (error
     23                        'execute
     24                        "shell command failed with non-zero exit status"
     25                        cmd r))))))
    3326          cmds)))
    3427    (if status (apply values ss) (void))))
    3528