gmoque has asked for the wisdom of the Perl Monks concerning the following question:
Monks:
Does anyone knows how to close a pipe catching the event using SIG{INT}? When I run the code below and I send Ctrl+C I go into the sub end but it looks like the telnet session never closes.*
Here is my code:
#!/usr/bin/perl $SIG{INT} = \&end; open (TELNET, '-|', "telnet 192.168.1.1 6088"); while(<TELNET>) { $arr = <TELNET>; $arr =~ s/[\r\n](.....):(.*)/<p class="$1">$1:$2<\/p>/; print $arr; } sub end { print "Closing the session ...\n" # close FH; close TELNET; print "Session closed!\n" exit; }
Any suggestions so the Telnet session won't hung up?
*NOTE: The telnet session is done to a terminal that just outputs text (log), I don't have to login or type anything after opening the telnet.
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I close a pipe
by BrowserUk (Patriarch) on Dec 14, 2008 at 07:15 UTC | |
by gmoque (Acolyte) on Dec 16, 2008 at 02:15 UTC | |
|
Re: How do I close a pipe
by f00li5h (Chaplain) on Dec 14, 2008 at 04:58 UTC | |
by gmoque (Acolyte) on Dec 14, 2008 at 05:14 UTC | |
by ysth (Canon) on Dec 14, 2008 at 06:34 UTC |