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.

Replies are listed 'Best First'.
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