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.


In reply to Unexpected termination on "print" by mlawren

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.