Use of tee command promptly even for one command
Asked Answered
P

3

6

I am new to using tee command.

I am trying to run one of my program which takes long time to finish but it prints out information as it progresses. I am using 'tee' to save the output to a file as well as to see the output in the shell (bash).

But the problem is tee doesn't forward the output to shell until the end of my command. Is there any way to do that ?

I am using Debian and bash.

Portiaportico answered 22/5, 2012 at 21:28 Comment(0)
A
3

This actually depends on the amount of output and the implementation of whatever command you are running. No program is obliged to print stuff straight to stdout or stderr and flush it all the time. So even though most C runtime implementation flush after a certain amount of data was written using one of the runtime routines, such as printf, this may not be true depending on the implementation.

It tee doesn't output it right away, it is likely only receiving the input at the very end of the run of your command. It might be helpful to mention which exact command it is.

Ayah answered 22/5, 2012 at 21:33 Comment(2)
You mentioned an excellent point! I forgot about the flushing. The command is one of my own C program. I added the fflush after my printf. Now it's working. Thank you very much for the prompt help.Portiaportico
@Portiaportico Hasan: glad it works for you now. It's an oft overlooked behavior, also in various scripting languages.Ayah
I
1

The problem you are experienced is most probably related to buffering. You may have a look at stdbuf command, which does the following:

stdbuf - Run COMMAND, with modified buffering operations for its standard streams.

Indecorum answered 22/5, 2012 at 21:44 Comment(0)
P
0

If you were to post your usage I could give a better answer, but as it is

(for i in `seq 10`; do echo $i; sleep 1s; done) | tee ./tmp

Is proper usage of the tee command and seems to work. Replace the part before the pipe with your command and you should be good to go.

Paten answered 22/5, 2012 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.