in reply to Re^2: SIGINT and system calls
in thread SIGINT and system calls

I'm surprised that that works on windows. Both select and signals are pretty unixy for the windows ports to emulate. I didn't know they could do that at all.

You're right that I omitted a way out of the while select loop. Probably last if 1 > $bytes; at the end of the loop would do it. I'll edit that into the original.

Update: Yes, concatenation in the loop would work fine, or if you wanted to get fancy I think you could say,

my $result; while (select my $rd = $rin, undef, undef, 60) { my $bytes = sysread *CMD, substr($result, -1), 4096; last if 1 > $bytes; }
Or else you could use the offset argument of sysread to position at the end of $result.

The 60 second timeout is new, too. Adjust to taste.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^4: SIGINT and system calls
by Anonymous Monk on Jan 20, 2005 at 05:59 UTC
    That works well to break the loop.

    What about putting the results back into a variable (such as $results)? Do I need to do a concatenation in the while( ... $results .= $buf; ... ) or is there a better way to store the output in a variable?
    print "I am finished with my task. My results are: \n"; # where are my results stored if I want them in a variable? # print $results;

    Thanks again!
Re^4: SIGINT and system calls
by Anonymous Monk on Jan 20, 2005 at 17:20 UTC
    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!