in reply to not waiting for external command to complete before getting the output

Try
open PROG,"program|" or die "Cannot fork"; while (<PROG>) { # do stuff... }
This also depends on your called program not buffering its output.

see perlopentut

  • Comment on Re: not waiting for external command to complete before getting the output
  • Download Code

Replies are listed 'Best First'.
Re: Re: not waiting for external command to complete before getting the output
by hambo (Novice) on Apr 26, 2004 at 18:31 UTC
    cdrecord seems to be buffering output
    Thanks guys. Been away making supper. Now, Seems like this silly cdrecord thing is buffering the output. I tried what was suggested and noting was output until the enture cd had completed the record (which of course by that stage is way too late). So, now the question is: how do I get hold of this output without hacking cdrecord?
    perl -e 'open (FD1, "/usr/bin/cdrecord -vs -dummy -eject /mnt/test/Deb +ian/2disc.iso |"); while (<FD1>) { $_ =~ s/^M//g; print $_ if /^Track/; }; close (FD1)
    My output looks like:
    Track 01: 0 of 47 MB written.Track 01: 1 of 47 MB written (fifo 96%).....etc.

    Thanks for the help so far.
    Cheers
    H