Hi Monks,

the following code runs really strange and I don't know why.
use strict; use warnings; use IPC::Open3; &run; sub run { while ( 1 ) { eval { &_run }; print $@ if $@; sleep 10; } } sub _run { my ($wtr, $rdr, $err); my (@output, $pid); eval { $pid = IPC::Open3::open3($wtr, $rdr, $err, 'blubb'); while (my $line = <$rdr>) { chomp($line); push @output, "out: $line"; } close($wtr) if $wtr; close($rdr) if $rdr; close($err) if $err; waitpid $pid, 0; }; print "$_\n" for @output; }
If the function _run is call in a eval block then it produces every 10
seconds a new process. If it runs without eval, then it runs correctly.
I tried the same with IPC::Cmd, but there exists the same problem.
use strict; use warnings; use IPC::Cmd; &run; sub run { while ( 1 ) { eval { &_run_cmd }; print $@ if $@; sleep 10; } } sub _run_cmd { my( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = IPC::Cmd::run( command => 'blubb', verbose => 0 ); print $success, "\n"; }
Why does eval makes it so strange?

Thank you for helping.

In reply to Problems with IPC::Open3 by Anonymous Monk

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.