linux - can tee redirect a fifo to stdout in c programming? -


i want redirect fifo stdout , read doc http://man7.org/linux/man-pages/man2/tee.2.html

it says tee(int fd_in, int fd_out,...)

but when throw fifo fd 1st arguments, says invalid error.

#define _gnu_source #include <stdlib.h> #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <limits.h> int main() {     int num = 0, fd;     char fifo[] = "/tmp/tmpfifo";      fd = open(fifo, o_rdonly, 0644);     if (fd == -1) {         perror("open");         exit(exit_failure);     }     num = tee(fd, stdout_fileno, int_max, splice_f_nonblock);     if (num < 0) {         perror("tee");         exit(exit_failure);     }     fprintf(stderr,"%d\n", num);     return 0; } 

the console shows: tee:invalid arguments. 1st argu should stdin?

from tee()'s man pages:

tee() duplicates len bytes of data pipe referred file descriptor fd_in pipe referred file descriptor fd_out.

so, both file descriptors must refer pipes.

in call tee():

tee(fd, stdout_fileno, int_max, splice_f_nonblock); 

fd fifo, in turn pipe, stdout_fileno may not refer pipe.

stdin_fileno , stdout_fileno not pipes.


if want stdout_fileno refer pipe, can run program @ shell's command line in following way:

yourprogram | cat 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -