dagolden / Capture-Tiny

(Perl) Capture STDOUT and STDERR from Perl, XS or external programs
http://search.cpan.org/dist/Capture-Tiny/
39 stars 19 forks source link

Unexpected extra line of output #13

Open ronsavage opened 11 years ago

ronsavage commented 11 years ago

This is for Perl v5.14.2:

!/usr/bin/env perl

use feature 'say'; use strict; use warnings;

use Capture::Tiny 'capture';

--------------------------

say capture{system('echo', 'Hello World')};

This outputs 2 lines. The 0 is unexpected:

Hello World 0

When using something like:

my($stdout) = capture{system('echo', 'Hello World')};

say $stdout;

Then the output contains just the 1 expected line.

Any ideas?

ronsavage commented 11 years ago

Errr, that ugly black line is actually a hash-prefixed comment of hyphens. Just ignore it.

dagolden commented 11 years ago

Was that capture or capture_stdout? I suspect the latter.

The "0" is probably the return value of system. The capture commands return the output and the return value of the block so you can say my $foo = capture { ... }.

So you don't really want to directly say the results of capture.

ronsavage commented 11 years ago

Hi David

On 25/09/13 21:01, David Golden wrote:

Was that capture or capture_stdout? I suspect the latter.

Yes. I was switching the code back and forth between the 2.

The "0" is probably the return value of system. The capture commands return the output and the return value of the block so you can say my $foo = capture { ... }.

So you don't really want to directly say the results of capture.

No :-).

Ron Savage http://savage.net.au/ Ph: 0421 920 622