(define (call-with-output-processor-sock command proc)
"Call COMMAND, a list of strings representing an executable with its
arguments, and apply PROC to every line printed to standard output or
standard error. Return the exit status of COMMAND."
(match (socketpair PF_UNIX SOCK_STREAM 0)
((in . out)
(let ((err (dup out)))
(catch #true
(lambda ()
(let ((thread
(parameterize ((current-error-port err)
(current-output-port out))
(call-with-new-thread
(lambda ()
(let ((return
(status:exit-val
(apply system* command))))
(close-port err)
(close-port out)
return))))))
(let loop ()
(match (read-line in 'concat)
((? eof-object?)
(join-thread thread))
(line
(proc line)
(loop))))))
(lambda (key . args)
(for-each
(lambda (port)
(false-if-exception (close-port port)))
(list err out in))
(apply throw key args)))))))