<p>Have you experimented with calling the shell as a single command, passing along the string to execute? E.g.</p>
<p>bash -c "<your series of commands>"</p>
<p>Garrett</p>
<div class="gmail_quote">On Dec 26, 2012 2:37 PM, "Gleb Peregud" <<a href="mailto:gleber.p@gmail.com">gleber.p@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Happy holidays, everyone!<br>
<br>
I want to run multiple commands in a single shell from my code through<br>
some sort of open_port({spawn, ...}). I have four requirements:<br>
1) I want it to work asynchronously (i.e. I start a command and I get<br>
it's results streamed to a process as it happens);<br>
2) I want to know exactly when a command finishes;<br>
3) Binary output should be handled properly;<br>
4) Changes in env variables should be preserved between commands.<br>
<br>
A naive sequence of os:cmd/1 or open_port({spawn, ...}) doesn't<br>
satisfy requirement 4.<br>
<br>
os:cmd/1 has a nice backend code in there, but it doesn't satisfy<br>
requirement 3. It has a bug. Try running length(os:cmd("head -c 1000<br>
/dev/urandom")).<br>
<br>
open_port({spawn, "/bin/sh -s -"}, [line]) with port_command/2 doesn't<br>
satisfy requirement 2.<br>
<br>
Any ideas how to implement it? Is there any library which does it?<br>
<br>
Cheers,<br>
Gleb<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>