[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lazy mode in tee
From: |
Tomáš Mudruňka |
Subject: |
lazy mode in tee |
Date: |
Sat, 14 Mar 2009 23:08:04 +0100 (CET) |
hello.
i was wroting small bash script which needs special behaviour of tee
and i needed to reimplement it.
The important lines looks like that:
while true; do
cat "$2" | ccrypt -e -K "$3" | tee-lazy "$1";
done &
This code listens on named pipe $2 and when somebody writes
something to it, it will encrypt the contents and save them to file
$1.
But with regular tee this can't work, because tee will fopen(...,
"wb") destination file imediatelly when started when no data are
actually coming thru pipe and it will of course delete the file
contents right after they are written. so it should be nice to have
something like "lazy mode", when tee opens file just after the first
byte arrives. here is my ugly alternative:
#include <stdio.h>
int main(int argc, char *argv[])
{
if(argc < 2) {
printf("Usage: %s output-file < input-file\n", argv[0]);
}
FILE *outfp;
outfp = 0;
unsigned int c;
while( (c = getchar()) != EOF ) {
if(!outfp) outfp = fopen(argv[1], "wb");
putc(c, outfp);
}
fclose(outfp);
return 0;
}
I hope there can be some similar like tee -l argument to enable
similar functionality because handling named pipes like that is very
usefull.
Thanks. Best regards
Harvie
- lazy mode in tee,
Tomáš Mudruňka <=