[erlang-questions] managing subprocesses

Timo Schrappe schrappe.t@REDACTED
Fri May 31 14:41:11 CEST 2013


The "&& echo 0 || echo 1" thing is indeed smart but still a dirty hack.

open_port works for me!

14> P = erlang:open_port({spawn, "asdsad23"}, [exit_status]).
#Port<0.601>
15> sh: line 0: exec: asdsad23: not found
15> flush().                                                 
Shell got {#Port<0.601>,{exit_status,127}}
ok

Thanks

On May 30, 2013, at 10:10 PM, Michael Truog <mjtruog@REDACTED> wrote:

> If you want to do it manually, you would be using:
> http://www.erlang.org/doc/man/erlang.html#open_port-2
> 
> Note that you can also do something like (if you only care about the exit code):
> 
> shell(Command, Arguments) ->
>    CommandSuffix = " && echo 0 || echo 1",
>    [Result | _] = os:cmd(lists:flatten(
>        io_lib:format(Command ++ CommandSuffix, Arguments))),
>    if
>        Result =:= $0 ->
>            ok;
>        Result =:= $1 ->
>            io:format("\"~s\" failed!~n", [io_lib:format(Command, Arguments)]),
>            error
>    end.
> 
> 
> 
> On 05/30/2013 12:52 PM, Timo Schrappe wrote:
>> Hello,
>> 
>> I am wondering that there isn't a great way for managing and parsing subprocesses (through os:cmd/1) and their output.
>> I spent some time with google and found erlexec which basically will do my job here. But it feels a bit cheesy to use an external module (or is it called application in erlang?) to use such a fundamental functionality.
>> 
>> I want to manage some shell scripts which will start some e.g. daemons.
>> 
>> 
>> What is the erly way to do that kind of things? Im specially interested in the exit code from the bash scripts.
>> 
>> 
>> - Timo
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130531/b3677311/attachment.htm>


More information about the erlang-questions mailing list