Ticket #496: shell-escaping.patch
File shell-escaping.patch, 1.5 KB (added by , 14 years ago) |
---|
-
shell.scm
1 1 ;;;; shell.scm 2 2 3 3 4 (module shell (execute run run* shell shell shell-verbose command)4 (module shell (execute run run* shell shell-verbose) 5 5 6 6 (import scheme chicken) 7 (use extras utils data-structures)7 (use data-structures posix) 8 8 9 9 10 10 (define shell-verbose (make-parameter #f)) 11 11 12 (define (command . cmds)13 (apply14 values15 (map (lambda (cmd)16 (string-intersperse (map ->string (flatten cmd))))17 cmds)))18 19 12 (define (execute cmds #!key status verbose) 20 13 (let ((ss 21 14 (map 22 15 (lambda (cmd) 23 (let ((cmd (commandcmd)))24 25 (printf " ~A~%~!" cmd))26 (let ((r (system cmd)))27 28 29 30 31 32 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)))))) 33 26 cmds))) 34 27 (if status (apply values ss) (void)))) 35 28