I have a script which automates a dump of some discs. As it goes along, it writes to standard output, and I want to log the output by redirecting to a file. Here's a fragement of the script showing the general structure:
sub perform_dump
{
print "\nDumping the discs...\n";
foreach my $disc (@discs) {
print "...$disc...\n";
local (*HIS_IN, *HIS_OUT, *HIS_ERR);
my $cmd = '/usr/sbin/ufsdump';
my @args = ('0luf', '/dev/rmt/1n', $disc);
my $pid = open3 (*HIS_IN, *HIS_OUT, *HIS_ERR,
$cmd, @args);
print while (<HIS_ERR>);
wait;
&barf ('dump-fail', $disc) if $? != 0;
}
}
...i.e. run ufsdump in a sub-process, grab the output and channel it to standard out of the perl process. The script works, but each time it print anything, it reprints
everything that's been sent to standard output since the start of the programme! Howvere, it only does this with the redirect to the file; writing to the terminal comes out as expected.
Is this a Perl bug, a module bug in IPC::Open3, a feature, or did I just screw up?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.