mes: system*: Support redirection.

* mes/module/mes/posix.mes (system*): Support redirection.
This commit is contained in:
Jan Nieuwenhuizen 2018-11-11 10:00:50 +01:00
parent b85db01e9b
commit ad9f78718f
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 10 additions and 1 deletions

View File

@ -49,7 +49,16 @@
(define (system* file-name . args)
(let ((pid (primitive-fork)))
(cond ((zero? pid) (apply execlp file-name (list args)))
(cond ((zero? pid)
(let ((out (current-output-port))
(err (current-error-port)))
(when (and (> out 0)
(not (= out 1)))
(dup2 out 1))
(when (and (> err 0)
(not (= err 2)))
(dup2 err 2))
(exit (apply execlp file-name (list args)))))
((= -1 pid) (error "fork failed:" file-name))
(else (let ((pid+status (waitpid 0)))
(cdr pid+status))))))