Created
February 23, 2020 02:05
-
-
Save ORESoftware/d0558fb64a0bfa3ce59e411fe5ba939b to your computer and use it in GitHub Desktop.
re-use node.js process to
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
cm_env_exp() { | |
rm -rf /tmp/srv-input | |
mkfifo /tmp/srv-input | |
rm -rf /tmp/srv-output | |
mkfifo /tmp/srv-output | |
( | |
( | |
tail -f /tmp/srv-input > >(node -e ' | |
const fd = fs.openSync("/tmp/srv-output", "w+"); | |
const s = fs.createWriteStream(null,{fd}); | |
// s.write("\n"); | |
process.stdin.resume().on("data", d => { | |
// console.log("d:", String(d)); | |
const v = String(d).split("="); | |
if(v === "EOF"){ | |
process.exit(0); | |
} | |
s.write(v.shift()); | |
s.write(v.join("")); | |
// s.write("\n"); | |
}); | |
') & | |
) | |
) &> /dev/null | |
node_pid="$!" | |
( | |
# sleep .15; | |
( | |
env | grep 'cm_' | grep -v 'BASH_FUNC' | grep -v 'cm_color' | while read line; do | |
echo "$line" > /tmp/srv-input | |
done; | |
echo "EOF" > /tmp/srv-input | |
) & | |
) # &> /dev/null | |
( | |
export kill_this="$BASHPID" | |
cat /tmp/srv-output | while read line; do | |
if [[ "$line" == 'EOF' ]]; then | |
kill -9 "$kill_this" | |
exit 0; | |
fi | |
echo -e "$line" | |
done; | |
) | |
# echo 'waiting' | |
# tail -f /tmp/srv-output | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment