Skip to content

Instantly share code, notes, and snippets.

@kuy
Created October 22, 2014 06:23
Show Gist options
  • Save kuy/eddc371d50b7a9525218 to your computer and use it in GitHub Desktop.
Save kuy/eddc371d50b7a9525218 to your computer and use it in GitHub Desktop.
Learning Named Pipe
#!/usr/bin/env bash
root=$(cd $(dirname $0); pwd)
pipe="/tmp/np-$$"
mkfifo $pipe
echo "np-main: pipe created: $pipe"
"$root/np-sub.sh" "$pipe" "$@" &
echo "np-main: from sub: $(cat $pipe)"
echo "np-main: exit code: $?"
rm -f $pipe
echo "np-main: pipe deleted"
#!/usr/bin/env bash
if [[ ! -z $2 ]]; then
echo "" >$1
echo "np-sub: error" >&2
exit 1
fi
echo "np-sub: named pipe!" >$1
echo "np-sub: success"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment