open (to read) and kill a pipe to a pipeby Anonymous Monk
|on Aug 26, 2010 at 20:19 UTC||Need Help??|
Anonymous Monk has asked for the
wisdom of the Perl Monks concerning the following question:
So I need to read the output of a command that outputs a lot of data... but I don't need all the data. I want to be able to stop after some point.
For just a single pipe to my script this works OK:
At the point the kill is issued, mycommand is terminated, life is good and we are ready to move on and process the next file.
... by the way, I'm on Windows XP, ActiveState Perl 5.8.8.
I'm not even sure what signal I should be sending with the kill (I tried 1, 2 and 9... 9 worked so that's what I am using).
What I want to do is:
Notice the pipe to a pipe... "gzip ... | mycommand |"
This works in the sense that it gunzips the file on the fly, and passes the data to mycommand, and then I get what I want in the script.
BUT it does not kill the gzip or mycommand processes when it gets to the "kill 9, $pid". Then it just sits at the close INPUT until the gzip and mycommand are done (which takes a few minutes).
Any ideas on how I should do the piping so I can kill the processes properly? Also, any suggestions on what signals to use in windows?