Appending to a file

cog on 2004-09-03T10:34:22

Not necessarily with Perl, though...

My current problem is: when redirecting output to a file, the file is apparently written only by the end of the process... I can't track its progress with something such as tail! :-|

I tried using tee, Perl, etc... it seems of no avail...

My purpose is a simple one:

mplayer *.mp3 -shuffle | grep Playing >> .now_playing

You can easily tell where this is going... I want to be able to see the music now playing by looking at the last line in the file :-)


How about something like this

link on 2004-09-03T13:19:19

use IO::File;
$now = IO::File->new(">>.now");
$now->autoflush(1);
open( MP , "mplayer *.mp3 -shuffle 2>/dev/null |");

while(<MP>)
{
    if(/Playing/)
    {
        print NOW $_;
    }
};

Re:How about something like this

cog on 2004-09-03T13:25:58

With some minor twitching (print $now), it works :-) Thanks :-)

Re:How about something like this

link on 2004-09-03T13:28:36

Actually that doesn't work but this does( must learn to test before posting)
use IO::File;

open(NOW,">>.now");
autoflush NOW 1;

open( MP , "mplayer *.mp3 -shuffle 2>/dev/null |");

while(<MP>)
{
    if(/Playing/)
    {
        print NOW $_;
    }
}

mprand

rjbs on 2004-09-03T13:44:56

If you wanted to use mpg123, and were willing to live with overkill, you could use this, with a bit of file IO added. I only mention it because it's only two days old and still in my head...

http://rjbs.manxome.org/hacks/perl/mprand