Created
November 30, 2017 22:39
-
-
Save ahogen/ee0775602600d6b0dba4f2d44d636b30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##################################################################### | |
# Alex Hogen (https://github.com/ahogen) | |
# | |
# Run the command provided, redirecting STDERR to STDOUT, effectivly | |
# reducing all output to a single output pipe, hence the name "spipe". | |
# This script is also capable of capturing some common kill codes | |
# and forwarding them to the child process. | |
# | |
# This script was originally written for executing some external | |
# programs in Julia (http://julialang.org/). These external programs | |
# were being silly and printing errors to stdout and "normal" output | |
# to stderr. To simplify matters, I wanted a singular pipe on the | |
# Julia side and this script was the fastest way for me to get that | |
# accomplished. | |
##################################################################### | |
prop_sigint() { | |
kill -2 ${child} | |
echo "[spipe.sh] Sent SIGINT to child process (pid ${child})" | |
} | |
prop_sigquit() { | |
kill -3 ${child} | |
echo "[spipe.sh] Sent SIGTERM to child process (pid ${child})" | |
} | |
prop_sigterm() { | |
kill -15 ${child} | |
echo "[spipe.sh] Sent SIGTERM to child process (pid ${child})" | |
} | |
# Trap and forward common termination signals to the child | |
trap prop_sigint SIGINT | |
trap prop_sigquit SIGQUIT | |
trap prop_sigterm SIGTERM | |
# Ampersand on the end tells shell not to wait for process to complete, | |
# but instead continue running. | |
#echo $@ | |
"$@" 2>&1 & | |
child=$! | |
# Wait for child process to finish before exiting | |
wait ${child} | |
EC=$? | |
echo "[spipe.sh] Exiting (code: ${EC})" | |
exit $EC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment