[erlang-questions] Running a Unix Subprocess

Ameretat Reith <>
Tue Sep 27 11:34:26 CEST 2016


On Tue, 27 Sep 2016 12:19:53 +0300
Zachary Kessin <> wrote:

> Hi all
> 
> I want to run a sub process that will connect via StdIn and StdOut. Is
> there an easy way to do this? I had thought to use a port but as the
> child process was not written with the assumption that it is running
> inside a port i don't want to have to prepend length bytes onto the
> inputs and outputs.
> 
> Is there an easy way to do this in erlang?
> 

User erlang:open_port [1].  Example:

erlang:open_port({spawn_executable, "/bin/cat"}, [eof, exit_status]).

This will open a port and execute "/bin/cat" in it, wait until standard
input is closed (eof), reply exit status after cat termination
(exit_status).  If you want process get standard input and output of
caller, pass use_stdio option.


1: http://erlang.org/doc/man/erlang.html#open_port-2


More information about the erlang-questions mailing list