Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. alias Porcelain.Process
  2. alias Porcelain.Result
  3.  
  4. defmodule Cmd do
  5. def run() do
  6. args = ["b"]
  7. opts = [
  8. in: "a\nb\nc\nb\nb\nd\nb\ne",
  9. out: {:send, self()},
  10. err: {:send, self()} # eksperimental -> This is the only thing that changed
  11. ]
  12. %Process{pid: pid} = Porcelain.spawn("grep", args, opts)
  13. handle_output(pid)
  14. end
  15.  
  16. def handle_output(pid) do
  17. receive do
  18. {^pid, :data, :out, data} ->
  19. IO.puts "data: #{data}"
  20. handle_output(pid)
  21. {^pid, :data, :err, data} ->
  22. IO.puts "error: #{data}"
  23. handle_output(pid)
  24. {^pid, :result, %Result{status: status}} ->
  25. IO.puts "status: #{status}"
  26. after
  27. 5_000 -> IO.puts "timeout"
  28. end
  29. end
  30. end
  31.  
  32. Cmd.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement