handle SIGPIPE

This commit is contained in:
Peter Kleiweg
2026-03-26 18:03:36 +01:00
parent b4d6d06146
commit d2e866720c
4 changed files with 38 additions and 2 deletions

1
.gitignore vendored
View File

@@ -25,6 +25,7 @@ Tzum/xml2txt
VRT/metadata
VRT/vrt
bin/ISOWeek
bin/flush
bin/score
bin/top20
bin/week2files

View File

@@ -11,6 +11,7 @@ all:
make -C Tzum
make -C VRT
make bin/ISOWeek
make bin/flush
make bin/score
make bin/top20
make bin/week2files
@@ -18,6 +19,9 @@ all:
bin/ISOWeek: cmd/ISOWeek/*.go
go build -o $@ $^
bin/flush: cmd/flush/*.go
go build -o $@ $^
bin/score: cmd/score/*.go
go build -o $@ $^

26
cmd/flush/flush.go Normal file
View File

@@ -0,0 +1,26 @@
package main
import (
"bufio"
"os"
"os/signal"
"syscall"
)
func main() {
doOUt := true
chSignal := make(chan os.Signal, 1)
signal.Notify(chSignal, syscall.SIGPIPE)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
select {
case <-chSignal:
doOUt = false
default:
}
if doOUt {
os.Stdout.WriteString(line + "\n")
}
}
}

View File

@@ -1,5 +1,7 @@
#!/bin/bash
PATH=/net/corpora/nlnieuws/bin:$PATH
PROGNAME=$0
usage() {
echo "
@@ -120,10 +122,13 @@ case $XN in
;;
esac
HEAD=''
TAIL=''
if [ $LIMIT -gt 0 ]
then
TAIL=" | head -n $LIMIT"
HEAD=" | flush | head -n $LIMIT"
else
TAIL=" | flush"
fi
if [ $USEPAGER = 1 ]
then
@@ -140,7 +145,7 @@ fi
search () {
# $'\t' in bash is een tab
CMD="alto $@ '$EXPR' '$TEMPLATE' | $SORT | uniq -c | sed -e 's/\([0-9]\) */\1\t/' | sort -f -k 2 2> /dev/null | sort -n -r -k 1,1 -s 2> /dev/null | column -t -s '"$'\t'"' -c 0 2> /dev/null$TAIL"
CMD="alto $@ '$EXPR' '$TEMPLATE' | $SORT | uniq -c | sed -e 's/\([0-9]\) */\1\t/' | sort -f -k 2 | sort -n -r -k 1,1 -s$HEAD | column -t -s '"$'\t'"' -c 0$TAIL"
if [ $VERBOSE = 1 ]
then
echo "$CMD"