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.
|