This script opens the fifo if it doesn't exist and then starts the writer process in the background. It then opens the other end of the FIFO by cat'ing it to /dev/null. IF you don't open both ends of the FIFO, then the open call will block.
This is the writer script, which simply echo's a line to the FIFO, sleeps a bit and then exits.#!/bin/sh # Make the FIFO (first time only) if [ ! -p "file.fifo" ] then mkfifo file.fifo fi # run script to write to FIFO and wait for it to finish ./writefifo.sh & cat file.fifo >/dev/null # open other end wait && echo "writer done" rm -f file.fifo exit 0
This seems to work fine for me, even when I Control-C the main script before the writer finishes. Do you have any processes still running after your primary Ctrl-C that may be blocking on an open call?#!/bin/sh echo "a line to the fifo" >> file.fifo sleep 5
---
echo S 1 [ Y V U | perl -ane 'print reverse map { $_ = chr(ord($_)-1) } @F;'
Warning: Any code posted by tuxz0r is untested, unless otherwise stated, and is used at your own risk.
In reply to Re: named pipe and "Text file busy"
by tuxz0r
in thread named pipe and "Text file busy"
by finpro
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |