On 7 November 2012 03:49, Keith Wright
<address@hidden> wrote:
> (define y (with-output-to-string (lambda()(system "date"))))
Tue Nov 6 21:42:41 EST 2012
> y
$2 = ""
The stdout of the system call does not go into the string,
why not?
For the same reason you cannot capture stdout of, say,
printf() in the native code to a file using
with-output-to-file
I am not qualified to judge if these are valid reasons, though.
I used the code below to achieve that.
Alexei
;;;
;;; Beware that writing to the same file from multiple workers is not
;;; going to end good:
;;;
(define (with-stdout-to-file file proc)
(with-output-to-file file
(lambda ()
(let ((dup-1 (dup 1)) ; make a dup of the current stdout
(fd (fileno (current-output-port))))
(dup2 fd 1) ; close stdout and redirect it to fd
(proc) ; execute thunk with stdout redirected to file
(dup2 dup-1 1) ; close file, stdout to original destination
(close dup-1))))) ; dont leak file descriptors