As petral pointed out, dd outputs its status messages on STDERR, not on STDOUT, but open and backticks only capture STDOUT. You can get around this by redirecting STDERR into the STDOUT file handle; the syntax is the same as on the shell command line, because Perl calls the Bourne shell to set up the redirection:
dd if=infile of=outfile 2>&1 Example Perl code:

my @r = `dd if=infile of=outfile 2>&1`; foreach (@r) { chomp; print "***$_***\n"; }
My dd on Linux does not output transfer speeds, just Records+PartialRecords in and out, so the program above printed:
***0+1 records in*** ***0+1 records out***

Note that this only works correctly when you use the of parameter of dd. If you redirect STDOUT using the shell instead, then Perl will not see the status messages, because they get embedded somewhere in the output file. For example:

# BAD CODE my @r = `dd if=infile >outfile 2>&1`;

I wrote this to give a dd specific example. In the perlfaq pointer (How can I capture STDERR from an external command?) that grep gave earlier, all the permutations of STDOUT vs. STDERR and open vs. backticks are discussed.


In reply to Re: dd related by Util
in thread dd related by anair

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.