Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does only capture part of output #10

Open
faxm0dem opened this issue Jun 6, 2013 · 4 comments
Open

Does only capture part of output #10

faxm0dem opened this issue Jun 6, 2013 · 4 comments

Comments

@faxm0dem
Copy link

faxm0dem commented Jun 6, 2013

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.

@dagolden
Copy link
Collaborator

dagolden commented Jun 6, 2013

What is RRDs and what is dump() doing?

David

On Thu, Jun 6, 2013 at 10:00 AM, Fabien Wernli notifications@github.comwrote:

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:

NaNNaNNaN
N
aNNaNNaN

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//issues/10
.

David Golden dagolden@cpan.org
Take back your inbox!http://www.bunchmail.com/
Twitter/IRC: @xdg

@faxm0dem
Copy link
Author

faxm0dem commented Jun 6, 2013

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

@dagolden
Copy link
Collaborator

dagolden commented Jun 6, 2013

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 notifications@github.comwrote:

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//issues/10#issuecomment-19069528
.

David Golden dagolden@cpan.org
Take back your inbox!http://www.bunchmail.com/
Twitter/IRC: @xdg

@faxm0dem
Copy link
Author

faxm0dem commented Jun 7, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant