Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Stop Command In Perl

by monsoon (Pilgrim)
on Jul 12, 2012 at 16:43 UTC ( #981437=note: print w/ replies, xml ) Need Help??


in reply to Stop Command In Perl

Why not just exit the loop with last and close the handle right after? I don't get though why you need a loop at all in this case.


Comment on Re: Stop Command In Perl
Re^2: Stop Command In Perl
by anshumangoyal (Scribe) on Jul 12, 2012 at 17:38 UTC
    Does closing the handler also kills the command?

      It would send a SIGPIPE which may or may not stop the command. This stuff is rather system specific and I'm not sure if what's the default on Windows. Just try.

      Otherwise if you really need a Ctrl-C to be sent: this form of open() returns the child's PID so you can use kill 2, $pid to send the signal.

        I think windows doesn't quite respect 'kill'. This (run on Windows 7 Professional, ActivePerl v5.12.4)
        perl -e "$pid = open PIPE, '-|', 'echo one two';$/=' '; while (<PIPE>) +{ print; kill 2, $pid}"
        outputs

        one two

        But this
        perl -e "$pid = open PIPE, '-|', 'echo one two';$/=' '; while (<PIPE>) +{ print; close PIPE}"
        outputs

        one

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981437]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-07-12 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls