O'Reilly logo

Elixir Cookbook by Paulo A Pereira

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

Using OS commands from within Elixir

It is possible to interact with the underlying operating system, execute OS commands, and get the result in our Elixir applications.

To do this, we will be using Alexei Sholik's porcelain (https://hex.pm/packages/porcelain).

We will build a very simple application that will accept a string defining a path and will return a list containing the entries for that path. We will use the ls unix command without leaving our Elixir application! We will also define a generic run function that will allow the running of any command we pass as the argument.

How to do it…

To create an application that interacts with the underlying operating system, we will follow these steps:

  1. Create a new application:
    > mix new os_commands
    

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