mlawren has asked for the wisdom of the Perl Monks concerning the following question:
I am seeing an issue with perl v5.20.2 exiting unexpectedly, and I don't know how to track down the source of the problem. Here's the code I'm trying to run:
use strict; use warnings; use Sys::Cmd 'spawn'; my $proc = spawn( 'file-not-found' } ); $proc->stdin->print("x\n"); $proc->wait_child;
Note that Sys::Cmd (my own module) fiddles around a lot with file descriptors (and that is most likely the actual issue). But the problem I have at the moment is that the perl process appears to be terminating on the print statement:
main::(j:5): my $proc = spawn( sub { print "hello\n" } ); DB<1> n main::(j:6): warn ref $proc->stdin; DB<1> n IO::Handle at j line 6. at j line 6. main::(j:7): $proc->stdin->print("x\n"); DB<1> n mark@mlt:~/src/sys-cmd$
If I change the print statement to print {$proc->stdin} "text\n" the it appears as if perl tries to run the statement twice!
main::(j:5): my $proc = spawn( sub { print "hello\n" } ); DB<1> n main::(j:6): warn ref $proc->stdin; DB<1> n IO::Handle at j line 6. at j line 6. main::(j:7): print {$proc->stdin} "x\n"; DB<1> n main::(j:7): print {$proc->stdin} "x\n"; DB<1> n mark@mlt:~/src/sys-cmd$
Without an error message I don't even know how to debug my actual issue. Any ideas?
p.s. I'm actually running a patched version of Sys::Cmd locally so you won't be able to re-create this without modification.
Update: I've created a new branch on github that you can check out to see what I'm trying to do:
$ git clone -b unexpected-termination git://github.com/mlawren/sys-cm +d $ cd sys-cmd $ ./unexpected-termination.pl Spawning process
Update 2: I just checked and no END block is run, and the exit value after termination is 141, which means nothing to me.
Update 3: The above errors were seen on Debian GNU/Linux. I *don't* see this behaviour with Perl 5.18.3 on Win32, where the test script runs to completion with normal error reporting.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected termination on "print" (pipe)
by tye (Sage) on Aug 14, 2015 at 14:28 UTC | |
by mlawren (Sexton) on Aug 14, 2015 at 20:35 UTC | |
by tye (Sage) on Aug 14, 2015 at 20:50 UTC | |
by mlawren (Sexton) on Aug 14, 2015 at 21:22 UTC | |
by afoken (Chancellor) on Aug 14, 2015 at 22:27 UTC | |
by AnomalousMonk (Archbishop) on Aug 14, 2015 at 22:29 UTC | |
| |
|
Re: Unexpected termination on "print"
by Anonymous Monk on Aug 14, 2015 at 09:40 UTC |