Line-buffering the output when forewarding to a file

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
akash_rawal
Posts: 229
Joined: Wed 25 Aug 2010, 15:38
Location: ISM Dhanbad, Jharkhand, India

Line-buffering the output when forewarding to a file

#1 Post by akash_rawal »

There's a line in pupdial:

Code: Select all

wvdial ${WVISP} ${WVPIN} ${WVAPN} ${WVWRLS} &> /tmp/pupdial.log &
/tmp/pupdial.log is updated after every line of output and can be viewed in wvdial connection log.

When I try to achieve a similar thing for the volume monitor, the output is full-buffered i.e. the output is not flushed after every line. Data gets written only when it has written about 1kb. None of the following work like I want.

Code: Select all

pup-volume-monitor &> "$LOG_FILE" #forewards stderr only

Code: Select all

pup-volume-monitor 2>&1 > "$LOG_FILE" #forewards stderr only

Code: Select all

pup-volume-monitor 2>&1 | cat > "$LOG_FILE" #full buffered output

Code: Select all

pup-volume-monitor 2>&1 | grep --line-buffered "" > "$LOG_FILE" #full buffered output
How can I achieve line buffering, please help!

User avatar
jemimah
Posts: 4307
Joined: Wed 26 Aug 2009, 19:56
Location: Tampa, FL
Contact:

#2 Post by jemimah »

The only way I know of is to add explicit buffer flushes to the C code with

Code: Select all

fflush(stdout)
.
[url]http://saluki-linux.com[/url]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

Cannot find any pup-volume-monitor on the forum .

&>FILE should mean stdout and stderr to FILE . Probably the ' &' fork at the very end of the line is needed here.

Some programs still issue output to the console even with &>FILE.

Post Reply