Does only capture part of output
I came across a case in which only part of STDOUT is being captured:
#!/usr/bin/perl -w
use strict;
use RRDs qw/dump/;
use Capture::Tiny qw/capture_stdout/;
my $dump = capture_stdout { RRDs::dump $ARGV[0] };
Output using any RRD file:
<v>NaN</v><v>NaN</v><v>NaN</v></row>
<!-- 2013-06-06 12:56:40 CEST / 1370516200 --> <row><v>N
aN</v><v>NaN</v><v>NaN</v></row>
</database>
</rra>
</rrd>
The ending of the file is still being sent to STDOUT.
The rest of the file (the beginning) is correctly passed to $dump.
What is RRDs and what is dump() doing?
David
On Thu, Jun 6, 2013 at 10:00 AM, Fabien Wernli [email protected]:
I came across a case in which only part of STDOUT is being captured:
#!/usr/bin/perl -w use strict;use RRDs qw/dump/;use Capture::Tiny qw/capture_stdout/; my $dump = capture_stdout { RRDs::dump $ARGV[0] };
Output using any RRD file:
NaN NaN NaN |
N aN NaN NaN The ending of the file is still being sent to STDOUT. The rest of the file (the beginning) is correctly passed to $dump.
— Reply to this email directly or view it on GitHubhttps://github.com/dagolden/capture-tiny/issues/10 .
David Golden [email protected] Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg
RRDs provides the bindings for the C library to rrdtool (XS). It extracts the binary data from the rrd data file and exports it to an XML representation
Sounds like rrdtool is doing something with filehandles directly instead of taking what's currently STDOUT. Not much can be done about that.
David
On Thu, Jun 6, 2013 at 3:48 PM, Fabien Wernli [email protected]:
RRDs provides the bindings for the C library to rrdtool (XS). It extracts the binary data from the rrd data file and exports it to an XML representation
— Reply to this email directly or view it on GitHubhttps://github.com/dagolden/capture-tiny/issues/10#issuecomment-19069528 .
David Golden [email protected] Take back your inbox! → http://www.bunchmail.com/ Twitter/IRC: @xdg
I also tried IO::CaptureOutput with the exact same result. The following code works with RRDs::dump:
sub capture_stdout (&) {
my $pid;
my $fh;
unless ($pid = open $fh, "-|") {
die "Can't fork: $!" unless defined $pid;
shift->();
exit 0;
}
# the following is a noop, as it seems RRDs::dump already waits for its child
while (waitpid(-1, &WNOHANG) > 0) { sleep 1 }
return $fh;
}
my $fh = capture_stdout { RRDs::dump $ARGV[0] };
my $dump;
$dump .= $_ while <$fh>;