0

I have an xterm window that I would like to continually display the output of a named pipe. However, there seems to be some buffering occurring, and I can't find where it is happening.

I open two terminals. In the first, I make a pipe and watch for anything sent to it.

mkfifo pipe
tail -f pipe

On the second terminal, I send two messages through the pipe, from a single process, separated by some time. I use stdbuf to make sure that the output of the command is unbuffered.

stdbuf -o0 bash -c 'echo hi; sleep 5; echo bye' > pipe

This works as expected, with the first terminal printing hi, then printing bye five seconds later.

However, if I run the tail -f pipe inside an xterm window, then the messages do not appear until the program exits. Clearly, there is some buffering being done, but I cannot find where it is. Is there a way to prevent xterm from buffering the output of programs?

My "normal terminal" uses PuTTY, ssh-ed from Windows 7 to Linux machine. On the Linux machine, uname -a returns Linux hostname 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u1 x86_64 GNU/Linux, and xterm -v returns XTerm(278).

  • This sounds very odd. Can you give some more details about how you're invoking the xterm? Sounds like it may be running a different shell, or there's something in your .bashrc or .profile which is setting a different environment. (Does the output of the 'env' command differ between the terminal and xterm?) – nickcrabtree Oct 10 '15 at 21:59
0

On my tests, the buffering only happens for the first run of the bash script. So

bash -c 'echo' > pipe; bash -c 'echo hi; sleep 5; echo bye' > pipe

does pretty much what you want, but with an extra newline at the top. (I didn't even need stdbuf).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.