I like the opportunity to get fancy, but I noticed an odd reaction of the sysread(). Using:
my $result; while (select my $rd = $rin, undef, undef, 60) { my $bytes = sysread *CMD, substr($result, -1), 4096; last if 1 > $bytes; } ... print "I am finished with my task. My results are: \n"; print $result."\n";
My output is:
I am finished with my task. My result are: Pinging google.com [216.239.37.99] with 32 bytes of data: Reply from 216.239.37.99:bytes=32 time=36ms TTL=244 Ping statistics for 216.239.37.99: Packets: Sent = 15, Received = 15, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 36ms, Maximum = 37ms, Average = 36ms
What happened to all of the other lines from the ping (should be 15 result lines)? I would expect it to be:
I am finished with my task. My result are: Pinging google.com [216.239.37.99] with 32 bytes of data: Reply from 216.239.37.99: bytes=32 time=37ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=36ms TTL=244 Reply from 216.239.37.99: bytes=32 time=37ms TTL=244 Reply from 216.239.37.99: bytes=32 time=37ms TTL=244 Reply from 216.239.37.99: bytes=32 time=37ms TTL=244 Ping statistics for 216.239.37.99: Packets: Sent = 15, Received = 15, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 36ms, Maximum = 37ms, Average = 36ms
What happens that makes the $result apparently overwrite the output of the *CMD? I would still want to output the live results and set the variable, so would it be best to use the concatenation? I can't print $result in the loop, since that would contain all of the output, not just that loop's progress.

Also, why is the sysread() length set to 4096. Does that have a significant value?

Thanks!

In reply to Re^4: SIGINT and system calls by Anonymous Monk
in thread SIGINT and system calls 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.