in reply to named pipe and "Text file busy"
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: named pipe and "Text file busy"
by finpro (Novice) on Nov 25, 2007 at 08:20 UTC | |
by tuxz0r (Pilgrim) on Nov 25, 2007 at 17:41 UTC | |
by finpro (Novice) on Nov 25, 2007 at 20:50 UTC | |
by tuxz0r (Pilgrim) on Nov 25, 2007 at 21:35 UTC | |
by finpro (Novice) on Nov 26, 2007 at 13:36 UTC | |
|