Closed negrel closed 3 weeks ago
I'm not a windows developer but it seems that janet_make_pipe
always return blocking pipe on windows, ignoring the mode argument.
Just pushed some changes to help address this by adding some extra options to os/pipe
: https://github.com/janet-lang/janet/commit/accac6c6621bc7eb109aed50c8751c64ce0354f3
The following code should now work as both yes
and tr
should receive unmodified file descriptors and therefor avoid any strange behaviors.
(def [pipe-r pipe-w] (os/pipe :RW))
(pp (ev/gather
(ev/spawn
(def proc (os/spawn @["yes"] :epx { :out pipe-w }))
(os/proc-wait proc)
(ev/close pipe-w))
(ev/spawn
(def proc (os/spawn @["tr" "y" "Y"] :epx { :in pipe-r }))
(os/proc-wait proc)
(ev/close pipe-r))))
I saw a lot of Ys :)
(Warning: link to video)
It works well on my linux though it doesn't work on Windows because
os_pipe
calls janet_stream
that calls janet_register_stream
which call CreateIoCompletionPort
with a handle that doesn't support overlapped IO.
This should now work on windows with some code to handle streams that don't support overlapped IO (they simply are not registered). Closing.
I'm currently building a shell DSL for Janet and I'm trying to pipe stdout of a process to stdin of another process.
I have the following code:
Here is the output:
The number of
Y
lines is always 32768 (2 << 14) or 0. After looking at the source code of Janet it seems that all pipe created using(os/pipe)
are asynchronous (O_NONBLOCK
).The same code with a patched version of janet that returns synchronous pipe works well.
Does adding optional parameter to
(os/pipe)
to support synchronous pipe is conceivable ? Should I submit a PR ?Context: https://janet.zulipchat.com/#narrow/stream/409517-help/topic/How.20to.20pipe.20output.20of.20process.20as.20input.20of.20another.20process.20.3F/near/456186185 This is related to https://github.com/janet-lang/janet/issues/592 I believe.