Created
May 3, 2012 18:04
-
-
Save pietern/2587670 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
#!/usr/bin/env bash | |
set -e | |
set -x | |
path=$(mktemp -d) | |
rd=$path/rd | |
wr=$path/wr | |
mkfifo $rd | |
mkfifo $wr | |
nc $@ < $rd | grep --line-buffered "^+PONG" > $wr & | |
( | |
# Wait for PONG in the background | |
( | |
read foo | |
) < $wr & | |
# Send stdin and sentinel PING | |
cat | |
printf "PING\r\n" | |
# Wait for PONG (before closing $rd, which terminates `nc`) | |
wait | |
) > $rd | |
# Clean up | |
rm -rf $path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment