Ok, here you go, this works, tested on linux. It uses sysread to get the output, and it gets around the \r problem.
#!/usr/bin/perl use warnings; use IPC::Open3; #cdrecord sends a /r (no newline) to output status #so it is difficult to get output my $pid = open3(\*WRITE, \*READ,0,"/usr/bin/cdrecord -v -dummy -eject +dev=1,1,0 my.iso"); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ select(undef,undef,undef,.01); if( sysread \*READ,$output,1024 ){ print "$output\n"; }else{ print "finished\n"; exit; } }
OUTPUT from my testing:
Track 01: 89 of 97 MB written (fifo 100%) [buf 99%] 27.3x. Track 01: 90 of 97 MB written (fifo 100%) [buf 99%] 26.5x. Track 01: 91 of 97 MB written (fifo 98%) [buf 99%] 27.3x. Track 01: 92 of 97 MB written (fifo 100%) [buf 99%] 26.6x. Track 01: 93 of 97 MB written (fifo 98%) [buf 99%] 27.4x. Track 01: 94 of 97 MB written (fifo 100%) [buf 99%] 26.6x. Track 01: 95 of 97 MB written (fifo 100%) [buf 99%] 27.4x. Track 01: 96 of 97 MB written (fifo 100%) [buf 99%] 28.3x. Track 01: 97 of 97 MB written (fifo 100%) [buf 99%] 27.5x. Track 01: Total bytes read/written: 102400000/102400000 (50000 sectors +). Writing time: 42.959s Average write speed 15.5x. Min drive buffer fill was 99% Fixating... WARNING: Some drives don't like fixation in dummy mode. Fixating time: 26.760s /usr/bin/cdrecord: fifo had 1613 puts and 1613 gets. /usr/bin/cdrecord: fifo was 0 times empty and 872 times full, min fill + was 85%. finished

I'm not really a human, but I play one on earth. flash japh

In reply to Re: not waiting for external command to complete before getting the output by zentara
in thread not waiting for external command to complete before getting the output by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.