[erlang-questions] can a program launched with open_port({spawn, Cmd}, Options) remain running after the port closes?

Tim Watson watson.timothy@REDACTED
Thu Sep 27 20:47:37 CEST 2012


Guys,

On 27 Sep 2012, at 13:18, Erik Søe Sørensen wrote:
> 2012/9/27 Jesper Louis Andersen <jesper.louis.andersen@REDACTED>
> I remember this was something I had going. Let me dig code:
> 
> ----
> #!/bin/sh
> 
> (cat && kill 0) | opentracker $*
> Nice incantation. I was just about to suggest using a wrapper program, but I probably wouldn't have thought of that variation.
>  
> ----
> 
> So the trick is that the … && kill 0 part sends a kill signal to all processes in the current process group. This lets you stop another process since cat(1) understands what happens when stdin is closed and handles it accordingly.
> 
> I've only used it in tests though so it may need work for real programs
> Such as replacing "&&" with ";" ? :-)
> Just in case someone came along and killed the cat. (Can't at the moment imagine other scenarios where cat would exit with non-zero return values, but they probably exist.)
> 
> Also, replace $* with "$@" (including the quotes), for proper handling of parameters with spaces in them and such.

This works a treat, with some minor modifications. Thanks for pointing it out!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120927/9e98f471/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120927/9e98f471/attachment.bin>


More information about the erlang-questions mailing list