crazyinsomniac has asked for the wisdom of the Perl Monks concerning the following question: ⭐ (programs and processes)
I've got a commandline script, and I wanted to do some stuff before ending the program if somebody hit Ctrl^C.
If I add exit; or die; at the end of myhand, perl crashes (PERL caused an exception c0000026H in module KERNEL32.DLL at 015f:bff88510.).
I'm using ActivePerl and I've tried:
I need to hit Ctrl^c twice to kill the program.#!/usr/bin/perl -w use strict; $SIG{INT}=\&myhand; sub myhand { print "\n caught $SIG{INT}",@_,"\n"; } print "program started \n"; while(1){sleep 1;}
If I add exit; or die; at the end of myhand, perl crashes (PERL caused an exception c0000026H in module KERNEL32.DLL at 015f:bff88510.).
How do I fix this?
I've read perlman:lib:sigtrap and I've also tried:
which should be the same as my first example, but it also doesn't work (same errors as before).use sigtrap 'handler' => \&myhand, 'INT'; sub myhand { print "\n caught $SIG{INT}",@_,"\n"; } print "program started \n"; while(1){sleep 1;}
Originally posted as a Categorized Question.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I trap $SIG{INT} ( sigint aka Ctrl^c )?⭐
by crazyinsomniac (Prior) on Jul 01, 2001 at 13:18 UTC | |
Re: How do I trap $SIG{INT} ( sigint aka Ctrl^c )?
by Anonymous Monk on Feb 26, 2003 at 16:00 UTC | |
Re: How do I trap $SIG{INT} ( sigint aka Ctrl^c )?
by thayer (Sexton) on Jul 15, 2004 at 07:44 UTC | |
Re: How do I trap $SIG{INT} ( sigint aka Ctrl^c )?
by LH2007 (Initiate) on Oct 25, 2007 at 14:40 UTC |
Back to
Seekers of Perl Wisdom