Skip to content

Instantly share code, notes, and snippets.

@patmaddox
Created December 1, 2022 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmaddox/e7c4a105b5aa9bf5a5d185ba7175feff to your computer and use it in GitHub Desktop.
Save patmaddox/e7c4a105b5aa9bf5a5d185ba7175feff to your computer and use it in GitHub Desktop.
elixir port wrapper
# Start the program in the background
exec "$@" &
pid1=$!
# Silence warnings from here on
exec >/dev/null 2>&1
# Read from stdin in the background and
# kill running program when stdin closes
exec 0<&0 $(
while read; do :; done
kill -KILL $pid1
) &
pid2=$!
# Clean up
wait $pid1
ret=$?
kill -KILL $pid2
exit $ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment