GaijinPunch has asked for the wisdom of the Perl Monks concerning the following question:

I think there's an easy solution for this, but all my searches come up with tons of the wrong hits. :( Basically, I'm running a command to an external program that dumps a bunch of text. I'm using open() to read it in.
open ( DUMP, "/path/to/prog argument=value |") || die $!
The problem is, the program does not exit. Is there a non-gypsy way of doing ctrl+c after I've gotten the relevant data?

Replies are listed 'Best First'.
Re: ctrl-c'ing
by BrowserUk (Patriarch) on Apr 14, 2005 at 06:19 UTC

    my $pid = open ( DUMP, "/path/to/prog argument=value |") or die $!; ... # Process input kill 2, $pid; ## send the process SIGINT

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco.
    Rule 1 has a caveat! -- Who broke the cabal?
      very nice. Thank you.
Re: ctrl-c'ing
by brian_d_foy (Abbot) on Apr 14, 2005 at 09:46 UTC

    Have you tried closing the DUMP filehandle?

    In some programs where I've experienced this sort of thing, I've used IPC::Open2 to get read and write filehandles to the external process, then closed the write filehandle when I was done.

    It really depends on what the program is expecting and what it is trying to do, though.

    --
    brian d foy <brian@stonehenge.com>
Re: ctrl-c'ing
by inman (Curate) on Apr 14, 2005 at 09:15 UTC
    Have you determined the reason why the program doesn't exit? Is it waiting for user interaction or some other signal? You should avoid terminating a program in a way that it wasn't expecting as the program doesn't get a chance to tidy up.