Subj : Re: /dev/tty: all output, too? To : comp.os.linux,comp.os.linux.misc From : nobody Date : Thu Aug 26 2004 10:41 pm Aarlo Stone Fish spewed this unto the Network: > I am trying to write a program that reads all text output (and then does > something with it). It seems that /dev/std{out,in,err} and /dev/tty only > release data input by the user to the terminal. Is there any way for me to > capture all things like this: > char c; > c = 'h'; > write(1, &c, sizeof(c)); > I fork() and have the parent process continue with its regular writing and the > child process read from something like "/dev/tty". One thing you can do is use a pipe. Use the pipe(2) function to create a pipe. Close file descriptor 1 and use dup2(2) to replace it with the output end of the pipe. The child process then reads from the input end of the pipe and receives everything that the parent process writes. If you're trying to capture the output of a separate program, have your program read from stdin, and use the shell to set up a pipeline: generate-output | do-something-with-it When you do this, whatever goes to stdout of generate-output gets redirected to the stdin of do-something-with-it. .