I already read that; your blog is on my RSS feed list :)
I am *totally* new to both Erlang and Elixir, and didn't even know ports
existed until I read your post. And that is when I switched my code
from using Task.async/await(System.cmd(...)) to "Port.open".
But my needs were much simpler -- a pure shell command with only
stdout/stderr, no stdin, no "interaction" of any kind, no need to
pack/unpack, etc., so I glossed over most of it.
Speaking of "shameless", I am ashamed to say I even briefly glanced
through the code, but failed to notice that all the receive statements
shown in the previous code snippets in the main article had now
disappeared, to be replaced by handle_info. Even if I had noticed, I
may not have realised the significance of that change :-(
I'll take this opportunity to thank you for your excellent blog; I'm
learning a lot from it, though perhaps a bit slower than most :)
regards
sitaram
> On Thursday, August 20, 2015 at 12:21:40 PM UTC+2, Sitaram Chamarty wrote:
>
> Hi,
>
> I'm puzzled by some odd behaviour when listening for messages from a
> "Port", within a GenServer module.
>
> This module is supposed to take in an arbitrary number of shell
> commands, and keep "N" of them running at any given time. As soon as
> one command finishes, the next waiting command starts running.
>
> That might look like `xargs -P` but xargs prints all the output jumbled
> up; this code collects each shell command's output and prints it in one
> chunk when the command is done.
>
> I use the messages that `Port.open(spawn_executable ...` puts out to do
> this. Each line becomes a ":data" message, and at the end you get a
> ":exit_status" message. I wait for those exit messages, then -- based
> on the port in that message, grab all the data messages for that port
> and print them.
>
> Unforunately, some messages (not always the same ones either) are always
> lost. (And if an ":exit_status" message is lost, that command is never
> recognised to have completed!)
>
> Curiously, if I replace all of this with an Agent instead, it all works
> fine!
>
>
https://gist.github.com/sitaramc/7b0c11d94a90d1e5273a <
https://gist.github.com/sitaramc/7b0c11d94a90d1e5273a> has 3 files:
> server.ex (the one that fails), agent.ex (works great!) and helper-1.sh
> (a shell helper command; 3 lines of code and that's includig a "sleep"
> command!)
>
> To view this discussion on the web visit
https://groups.google.com/d/msgid/elixir-lang-talk/6137a239-fc27-469e-84d5-2678895ae789%40googlegroups.com <
https://groups.google.com/d/msgid/elixir-lang-talk/6137a239-fc27-469e-84d5-2678895ae789%40googlegroups.com?utm_medium=email&utm_source=footer>.