O'Reilly logo

Adopting Elixir by Jose Valim, Bruce Tate, Ben Marx

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Strategy 2: Communicating via I/O with Ports

Ports provide a safer alternative to integrate with external software. Each port starts the third-party software as a separate process in the operating system. If that port terminates, your Elixir code gets a message, and you can act accordingly. A segmentation fault in the external port won’t bring your Elixir system down.

It is possible that you’ve already spawned ports in your Elixir applications, like this:

 System.cmd("elixir", ["-e", "IO.puts 21 * 2"])
 {"42\n", 0}

This command finds the elixir executable in your operating system and invokes it passing the command-line arguments -e, for code evaluation, and the contents IO.puts 21 * 2. Then System.cmd returns the result written to the standard ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required