[erlang-questions] Running multiple commands like os:cmd/1

Gleb Peregud <>
Thu Dec 27 12:30:46 CET 2012


This is a reasonable solution (similar to one I have implemented
yesterday here [1]), although there is still a very-very-very low risk
that when running "cat /dev/urandom; echo <UUID>" given UUID will be
written twice and things will go haywire. I wonder if it is at all
possible to make it 100% robust.

1: https://github.com/gleber/sh/blob/master/src/runner.erl#L66

On Thu, Dec 27, 2012 at 12:21 PM, Heinz Nikolaus Gies
<> wrote:
> open a shell via open_port and run commands with something like
> <command> ; echo <UUID> ;
> then you know the command ended when the UUID is outputted?
>
> Just a crazy idea :)
> On Dec 27, 2012, at 12:08, Gleb Peregud <> wrote:
>
>> On Thu, Dec 27, 2012 at 1:25 AM, Siraaj Khandkar <> wrote:
>>> Why does it have to be a single shell? What is wrong with multiple ports?
>>
>> It's because I want to preserve changes in env variables between calls
>> (see requirement 4), since I want to be able to run commands like ".
>> /opt/erlang/r15b/activate" to prepare environment for further
>> commands. Think of a sequence of commands run by CI server.
>>
>>>> 1) I want it to work asynchronously (i.e. I start a command and I get
>>>> it's results streamed to a process as it happens);
>>>
>>> If it really has to be a single shell, you can background each command
>>> and you can tell when each will finish, but I don't know how would you
>>> distinguish which output came from where.
>>
>> It's exactly the problem I am facing.
>>
>>>> open_port({spawn, "/bin/sh -s -"}, [line]) with port_command/2 doesn't
>>>> satisfy requirement 2.
>>>
>>> How about open_port with 'exit_status' and call erlang:now/0 when receiving
>>> {Port, {exit_status, ExitCode}} messages?
>>
>> One open_port can produce just one exit_status message. Not sure what
>> you mean here.
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list