Running a Unix Subprocess

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Running a Unix Subprocess

Zachary Kessin-2
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?

--
Zach Kessin
Twitter: @zkessin
Skype: zachkessin

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Running a Unix Subprocess

Ameretat Reith
On Tue, 27 Sep 2016 12:19:53 +0300
Zachary Kessin <[hidden email]> 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
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Running a Unix Subprocess

Jesper Louis Andersen-2
In reply to this post by Zachary Kessin-2
My advice is to use Serge Aleynikov's "erlexec" for this:

https://github.com/saleyn/erlexec

It is built for exactly the purpose of handling "bad UNIX processes" in a way which makes them somewhat more in alignment with what Erlang provides. In particular, you can receive monitor-like events if the external process dies. It also handles the close-down of UNIX processes, should the Erlang system die. And so on. In short, it solves a lot of problems you would have to solve yourself otherwise.


On Tue, Sep 27, 2016 at 11:19 AM, Zachary Kessin <[hidden email]> 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?

--
Zach Kessin
Twitter: @zkessin
Skype: zachkessin

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




--
J.

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Running a Unix Subprocess

Csaba Hoch-3
In reply to this post by Ameretat Reith
Here is a short example of starting a process and reading its stdout
with open_port (you need to modify it to pass your own stdin, but it
might be a useful example nevertheless):

http://erlang.org/pipermail/erlang-questions/2007-February/025210.html

Csaba

On Tue, Sep 27, 2016 at 11:34 AM, Ameretat Reith
<[hidden email]> wrote:

> On Tue, 27 Sep 2016 12:19:53 +0300
> Zachary Kessin <[hidden email]> 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
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions