Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Disable Control +C

by PilotinControl (Monk)
on Mar 12, 2013 at 18:37 UTC ( #1023034=perlquestion: print w/ replies, xml ) Need Help??
PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:

Hello Again Monks! I am using Activestate Perl, on WinXP, using Win32 modules, and I am having an issue with disabling the Control +C functions. I would like the users of the script to just be able to use the selections on the menu and quit the program using that selection instead of Ctrl+C

$SIG{INT}='IGNORE'; or $SIG{INT}= \&inthandler; sub inthandler { structure::begin(); }

All that does is go back to the main screen and Ctrl+C resumes normal actions. Any suggestions? Thanks!

Comment on Disable Control +C
Download Code
Re: Disable Control +C
by Not_a_Number (Parson) on Mar 12, 2013 at 19:11 UTC

    This works for me (ActiveState Perl 5.14 on WIndows 7):

    use 5.010; $SIG{INT} = 'IGNORE'; my $x = 1; while ( $x <= 5 ) { say $x++; sleep 1; }

    When I say 'works', I mean that Ctrl-C is disabled until until the programme ends (try it).

      Here is my code:

      #!/usr/bin/perl use 5.010; use warnings; use strict; printf (" #############################\n"); printf (" ########## TEST MENU ########\n"); printf (" #############################\n"); sleep(2); $SIG{INT} = 'IGNORE'; while(1) { printf ("WHAT DO YOU WANT TO DO\n"); printf (" * * * * *\n"); printf (" 1- Option\n"); printf (" 2- Option\n"); printf (" 5-Exit \n"); printf (" * * * * *\n"); my $choose = <STDIN>; chomp($choose); if($choose eq 1) { option->client; } elsif($choose eq 2) { option2(); } elsif($choose eq 5) { printf("Good Bye :-)\n"); sleep(2); exit(1); }; };

      When you hit control +c within the program it sends errors to the screen...it prohibits control +c to kill the program. I have to choose option 5 to exit which is what I want...now to avoid the errors? Thanks.

        Hello PilotinControl,

        You just need to loop on $choose until it is defined:

        ... my $choose = <STDIN>; $choose = <STDIN> until defined $choose; # <-- Add this line chomp $choose; ...

        That will remove the warnings you are currently seeing.

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1023034]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2015-07-03 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (53 votes), past polls