Skip to content

Instantly share code, notes, and snippets.

@luismbo
Created May 27, 2020 12:17
Show Gist options
  • Save luismbo/aa8a3c2599c9690d001ecf81629d7ab6 to your computer and use it in GitHub Desktop.
Save luismbo/aa8a3c2599c9690d001ecf81629d7ab6 to your computer and use it in GitHub Desktop.
Redirect stdout to REPL
CL-USER> (multiple-value-bind (read write) (sb-unix:unix-pipe)
(let ((read-stream (sb-sys:make-fd-stream read :buffering :line)))
(sb-thread:make-thread (lambda ()
(loop for line = (read-line read-stream nil nil)
while line do (write-line line *standard-output*))))
(sb-posix:dup2 write sb-sys:*stdout*)))
1
CL-USER> (progn (cffi:foreign-funcall "puts" :string "COME TO ME STDOUT!" :int)
(cffi:foreign-funcall "fflush" :pointer (cffi:null-pointer) :int))
0
COME TO ME STDOUT!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment