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

run \@cmd, '>pty>' causes warning in child if $^W=1 #131

Open
pmorch opened this issue Dec 19, 2018 · 0 comments
Open

run \@cmd, '>pty>' causes warning in child if $^W=1 #131

pmorch opened this issue Dec 19, 2018 · 0 comments

Comments

@pmorch
Copy link

pmorch commented Dec 19, 2018

Ok, so I realize $^W = 1 or its sister, running with she-bang: #!/usr/bin/perl -w is no longer good style. But we have legacy code that does that. And with that, run \@cmd, '>pty>' causes a warning as this demo will show.

Feel free to summarily close it if you think:

This is the submitter's own damn fault. Don't use $^W=1 or perl -w

#!/usr/bin/perl -w
# Yeah, one shouldn't use 'perl -w' or $^W=1 but some of our legacy code does.
$^W=1;

use strict;
use IPC::Run qw( run start finish );

# Like this or only in the child as done below:
#
# $SIG{__WARN__} = sub {
#     die "Dying because of warning: " . $_[0];
# };

my $outAndErr = '';
{
    # This neutralizes the "perl -w" above, and if enabled, the warning goes away
    # local $^W = 0;
    run(
        ['echo', 'hello world'],
        '>pty>',
        \$outAndErr,
        init => sub {
            $SIG{__WARN__} = sub {
                die "Dying because of child warning: " . $_[0];
            };
        }
    );
}
print $outAndErr;

Running this yields:

> ./ipc.pl 
Dying because of child warning: Filehandle STDIN reopened as $s1 only for output at /usr/share/perl5/IPC/Run.pm line 2623.
 at ./ipc.pl line 27.
> perl -MIPC::Run -E 'say $IPC::Run::VERSION'
20180523.0
> perl -V | head -n 1
Summary of my perl5 (revision 5 version 24 subversion 1) configuration

(Also tried it on perl 5.20 with the same result)

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