1
0
mirror of https://github.com/janet-lang/janet synced 2025-09-12 07:46:09 +00:00

Add {:err :out} option to os/spawn.

This special case in the os/spawn interface allows easily
redirecting both stderr and stdout to the same pipe.
This commit is contained in:
Calvin Rose
2025-04-05 17:30:46 -05:00
parent a9ff8b388f
commit bdab93c999
3 changed files with 28 additions and 1 deletions

View File

@@ -556,4 +556,20 @@
(ev/deadline 0.01 nil f true)
(assert-error "deadline expired" (resume f)))
# Use :err :stdout
(def- subproc-code '(do (eprint "hi") (eflush) (print "there") (flush)))
(defn ev/slurp
[f &opt buf]
(default buf @"")
(if (ev/read f 0x10000 buf)
(ev/slurp f buf)
buf))
(def p (os/spawn [;run janet "-e" (string/format "%j" subproc-code)] :px {:out :pipe :err :out}))
(def [exit-code data]
(ev/gather
(os/proc-wait p)
(ev/slurp (p :out))))
(assert (zero? exit-code) "subprocess ran")
(assert (deep= data @"hi\nthere\n") "output is correct")
(end-suite)