I've got a script like:
#!/bin/bash
exec /usr/bin/some_binary > /tmp/my.log 2>&1
Problem is that some_binary
sends all of its logging to stdout, and buffering makes it so that I only see output in chunks of a few lines. This is annoying when something gets stuck and I need to see what the last line says.
Is there any way to make stdout unbuffered before I do the exec that will affect some_binary so it has more useful logging?
(The wrapper script is only setting a few environment variables before the exec, so a solution in perl or python would also be feasible.)
setvbuf
; hardly anyone bothers with that. Theexpect
system (of whichunbuffer
is a trivial application) uses black magic with Unix pseudo-terminal devices (ptys) to run programs with a terminal that isn't a real terminal so that the wrapped program doesn't buffer its output. It's clever, but be warned: most systems only have a limited number of ptys; a naturally unbuffered program is better. – Donal Fellowssome_binary
to do the right thing instead of relying on the black magic.expect
is great, but I don't want it here... – bstpierre