<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><span style="font-family: monospace; ">The "&& echo 0 || echo 1" thing is indeed smart but still a dirty hack.</span><br style="font-family: monospace; "><br style="font-family: monospace; "><span style="font-family: monospace; ">open_port works for me!</span><br style="font-family: monospace; "><br style="font-family: monospace; "><span style="font-family: monospace; ">14> P = erlang:open_port({spawn, "asdsad23"}, [exit_status]).</span><br style="font-family: monospace; "><span style="font-family: monospace; ">#Port<0.601></span><br style="font-family: monospace; "><span style="font-family: monospace; ">15> sh: line 0: exec: asdsad23: not found</span><br style="font-family: monospace; "><span style="font-family: monospace; ">15> flush().                                                 </span><br style="font-family: monospace; "><span style="font-family: monospace; ">Shell got {#Port<0.601>,{exit_status,127}}</span><br style="font-family: monospace; "><span style="font-family: monospace; ">ok</span><br style="font-family: monospace; "><br style="font-family: monospace; "><span style="font-family: monospace; ">Thanks</span></div><br><div><div>On May 30, 2013, at 10:10 PM, Michael Truog <<a href="mailto:mjtruog@gmail.com">mjtruog@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">If you want to do it manually, you would be using:<br><a href="http://www.erlang.org/doc/man/erlang.html#open_port-2">http://www.erlang.org/doc/man/erlang.html#open_port-2</a><br><br>Note that you can also do something like (if you only care about the exit code):<br><br>shell(Command, Arguments) -><br>    CommandSuffix = " && echo 0 || echo 1",<br>    [Result | _] = os:cmd(lists:flatten(<br>        io_lib:format(Command ++ CommandSuffix, Arguments))),<br>    if<br>        Result =:= $0 -><br>            ok;<br>        Result =:= $1 -><br>            io:format("\"~s\" failed!~n", [io_lib:format(Command, Arguments)]),<br>            error<br>    end.<br><br><br><br>On 05/30/2013 12:52 PM, Timo Schrappe wrote:<br><blockquote type="cite">Hello,<br><br>I am wondering that there isn't a great way for managing and parsing subprocesses (through os:cmd/1) and their output.<br>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.<br><br>I want to manage some shell scripts which will start some e.g. daemons.<br><br><br>What is the erly way to do that kind of things? Im specially interested in the exit code from the bash scripts.<br><br><br>- Timo<br>_______________________________________________<br>erlang-questions mailing list<br>erlang-questions@erlang.org<br>http://erlang.org/mailman/listinfo/erlang-questions<br><br></blockquote><br></blockquote></div><br></body></html>