;;; this works now ;;; with csi -s process-control.scm ;;; (it no longer hangs) (use posix srfi-18 miscmacros) (define (process* cmd #!optional args env) (let*-values (((in-in in-out) (create-pipe)) ((out-in out-out) (create-pipe)) ((err-in err-out) (create-pipe)) ((pid) (process-fork (lambda () (duplicate-fileno in-in fileno/stdin) (duplicate-fileno out-out fileno/stdout) (duplicate-fileno err-out fileno/stderr) (file-close in-out) (file-close in-in) (file-close out-in) (file-close out-out) (file-close err-in) (file-close err-out) (process-execute cmd args env))))) (file-close in-in) (file-close out-out) (file-close err-out) (let ((pip (open-input-file* out-in)) (pop (open-output-file* in-out)) (pep (open-input-file* err-in))) (set-buffering-mode! pip #:line) (set-buffering-mode! pop #:line) (set-buffering-mode! pep #:line) (values pip pop pid pep)))) ;; we can kill process with close-*-port: (define (tiger-dance) (receive (pip pop pid pep) (process* "cat" '()) (print "say hello") (display "hello\n" pop) (print "reading hello") (print "read: " (read-line pip)) (close-output-port pop) (close-input-port pip) (print "done"))) ;; but that causes strange 'bugs'? ;; this hangs: (print "running some spawn threads...") (repeat 10 (thread-start! tiger-dance)) (thread-sleep! 0.1) (print "we're done") ;;(print (read-line))