[erlang-questions] Erlang module for "controlling" (linux/unix) commands?

Tuncer Ayaz <>
Wed Sep 8 16:25:16 CEST 2010


On Wed, Sep 8, 2010 at 4:22 PM, Tuncer Ayaz wrote:
> On Wed, Sep 8, 2010 at 4:09 PM, Boris Mühmer wrote:
>> Is there a module for controlling (linux/unix) "shell" commands?
>>
>> I am looking for something more "special" than "os:cmd/1",
>> because I need to get the exit code of the command.
>
> Take a look at erlang:open_port/2.
>
> call erlang:open_port({spawn_executable, Command}, PortSettings)
> where PortSettings at least contains the exit_status option . You might
> also have to pass the use_stdio and {line, L} options.

To be precise: use_stdio and {line, L} might be useful. That's what
I wanted to write.

> The exit code will be delivered as a message:
> receive
>    {Port, {data, ...}} -> ...
>    {Port,{exit_status,Status}} -> ...
> end


More information about the erlang-questions mailing list