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

Garrett Smith <>
Mon Dec 31 17:23:51 CET 2012


+1

If you do a lot of system scripting, you might want to make bash a
tool-of-choice and use Erlang for control and supervisory functions.

On Mon, Dec 31, 2012 at 8:32 AM, Attila Rajmund Nohl
<> wrote:
> In this case you might want to put this "sequence of command" into a
> shell script (because they are essentially that) and execute the
> script. Use if, while, for, etc. in the script for controlling the
> execution.
>
> 2012/12/31 Gleb Peregud <>:
>> This would work, but since sometimes sequence of commands can change
>> depending on results of other commands in the sequence it does not fit
>> my case.
>>
>> On Fri, Dec 28, 2012 at 6:44 AM, Garrett Smith <> wrote:
>>> Have you experimented with calling the shell as a single command, passing
>>> along the string to execute? E.g.
>>>
>>> bash -c "<your series of commands>"
>>>
>>> Garrett
>>>
>>> On Dec 26, 2012 2:37 PM, "Gleb Peregud" <> wrote:
>>>>
>>>> Happy holidays, everyone!
>>>>
>>>> I want to run multiple commands in a single shell from my code through
>>>> some sort of open_port({spawn, ...}). I have four requirements:
>>>> 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);
>>>> 2) I want to know exactly when a command finishes;
>>>> 3) Binary output should be handled properly;
>>>> 4) Changes in env variables should be preserved between commands.
>>>>
>>>> A naive sequence of os:cmd/1 or open_port({spawn, ...}) doesn't
>>>> satisfy requirement 4.
>>>>
>>>> os:cmd/1 has a nice backend code in there, but it doesn't satisfy
>>>> requirement 3. It has a bug. Try running length(os:cmd("head -c 1000
>>>> /dev/urandom")).
>>>>
>>>> open_port({spawn, "/bin/sh -s -"}, [line]) with port_command/2 doesn't
>>>> satisfy requirement 2.
>>>>
>>>> Any ideas how to implement it? Is there any library which does it?
>>>>
>>>> Cheers,
>>>> Gleb
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> 
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list