Spawning Processes and Ports

What’s the proper way to setup a spawned process which has a Port(pipe) to an external program? I’m writing a toy program(something to experiment with Elixir) which accesses aspell(GNU aspell) via a Port(pipe) in a spawned process and I’ve got it working but I’m unsure if its the correct Elixir way. Any thoughts or comments? Please chime in.

An example of what I’m playing with…
https://bitbucket.org/snippets/G4143/7o8oq

The Gnu aspell’s pipe API…
http://aspell.net/man-html/Through-A-Pipe.html#Through-A-Pipe

1 Like

It should be wrapped in a GenServer for sure to manage error conditions. Also you might look at the Porcelain library for something like that as well.

1 Like

So outside of the GenServer step I can assume there is nothing wrong with my spawn/Port implementation?

Looks pretty normal, there is not much to them. :slight_smile:

The only reason I suggest Porcelain is it does the same, but you can control the lifespan of the port app better, like if it dies, locks up, if it does not close when the pipe is closed, etc… Ports are really designed for things that were made to speak ‘ports’, they just also happen to work decently with others too, Porcelain is good for everything else. :slight_smile:

In this use-case, it looks like the aspell fits ports really well, so even as-is you should be fine.