Skip to content

Instantly share code, notes, and snippets.

@codemac
Created October 7, 2016 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemac/7cd2625341ea34bd9a22a0146a270119 to your computer and use it in GitHub Desktop.
Save codemac/7cd2625341ea34bd9a22a0146a270119 to your computer and use it in GitHub Desktop.
guile test stderr
;;; note: source file /home/jmickey/tmp/./test.scm
;;; newer than compiled /home/jmickey/.cache/guile/ccache/2.0-LE-8-2.0/home/jmickey/tmp/test.scm.go
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/jmickey/tmp/./test.scm
;;; compiled /home/jmickey/.cache/guile/ccache/2.0-LE-8-2.0/home/jmickey/tmp/test.scm.go
what was stored in stdout:
<eond of os>
what was stored in stderr:
<eond of es>
what was stored in stdout:
help me i'm stdout
<eond of os>
what was stored in stderr:
<eond of es>
(use-modules (ice-9 popen))
(define (port-copy dst src)
(let ((c (read-char src)))
(if (eof-object? c)
dst
(begin (write-char c dst)
(port-copy dst src)))))
(define (print-outs one two)
(format #t "what was stored in stdout:~%~a~%<eond of os>~%" (get-output-string os))
(format #t "what was stored in stderr:~%~a~%<eond of es>~%" (get-output-string es)))
(let ((os (open-output-string))
(es (open-output-string)))
(parameterize ((current-error-port es))
(let ((rp (open-pipe* OPEN_BOTH; "dd" "if=/dev/zero" "of=/dev/zero" "bs=1" "count=20"
"logger" "-s" "help me i'm stderr")))
(port-copy os rp)
(status:exit-val (close-pipe rp))))
(print-outs os es))
(let ((os (open-output-string))
(es (open-output-string)))
(parameterize ((current-error-port es))
(let ((rp (open-pipe* OPEN_BOTH; "dd" "if=/dev/zero" "of=/dev/zero" "bs=1" "count=20"
"echo" "help me i'm stdout")))
(port-copy os rp)
(status:exit-val (close-pipe rp))))
(print-outs os es))
@codemac
Copy link
Author

codemac commented Oct 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment