-
Notifications
You must be signed in to change notification settings - Fork 45
Draft pages
Alexei Sholik edited this page Jun 6, 2014
·
2 revisions
This is a brain dump.
By using streams we can chain multiple external processes together:
alias Porcelain.Process
opts = [in: SocketStream.new('example.com', 80), out: :stream] %Process{out: grep_stream} = Porcelain.spawn("grep", ["div", "-m", "4"], opts)
IO.inspect Porcelain.shell("head -n 4 | wc -l", in: grep_stream).out
Caveat #1: we are using head above in order to stop reading input after the first 4 lines. Otherwise wc alone would wait indefenitily for EOF which cannot be signaled when using bare Erlang ports. The (currently not implemented) Goon driver fixes the issue.
Caveat #2: of course it would be more efficient to just use shell piping if portability to non-POSIX systems isn't required.