I need to duplicate stdout
and stderr
of a child proccess to multiple files.
I understand that i can use tee()
, but I haven\'t found e
Using tee
and splice
to write data from a handle to multiple other handles:
// Needs at least two targets, sentinel is INVALID_HANDLE_VALUE
int push_to_all(int source, ssize_t count, ...) {
va_list vl;
va_start(vl, count);
int target = va_arg(vl, int), next = va_arg(vl, int);
count = tee(source, target, count, SPLICE_F_NONBLOCK);
if(count <= 0) { va_end(vl); return count; }
while((target = next, next = va_arg(vl, int)) > 0) {
tee(source, target, count, 0);
va_end(vl);
return splice(source, 0, target, 0, count, 0);
}