cpan-authors / IPC-Run

https://metacpan.org/pod/IPC::Run
Other
21 stars 38 forks source link

"Unopened filehandle in output redirect" when using output functions and undef as timeout #128

Open kbucheli opened 6 years ago

kbucheli commented 6 years ago
#! /usr/bin/perl

use warnings;
use strict;

use IPC::Run qw(run timeout);
my $output = '';
my $func = sub { $output .= $_[0] };

my $input;
my $timeout;
run(['echo', 'foo'], \$input, $func, $func, $timeout);
print $output;

outputs:

Unopened filehandle in output redirect, command 1 at test.pl line 12.

Version: 20180523.0 (it used to work with v0.96)

ringerc commented 5 years ago

I've seen the same with string-references, which is bizarre and unexpected.

ringerc commented 5 years ago

At least in my case this was another symptom of #124 . I was passing an undef timer to IPC::Run::start and it somehow landed up being recognised as a GLOB reference, resulting in this error.

Changing

IPC::Run::start([..cmd_args..], ..., $timer);

to

my @ipcrun_args = ([...cmd_args...], ...)
push @ipcrun_args $timer if defined($timer);
IPC::Run::stat @ipcrun_args;

resolved the issue.