Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

How to catch CTRL+C?

 
webmaster forum
Activity
0%
 
New Poster
Posts: 10
Topics: 5
June 14, 2010, 09:24:53 PM

Hi all,

I want to catch the CTRL+C command and then let one of my own methods handle it.
Since CTRL+C terminates or aborts the program I thought I'd use the signal() function from the signal. h library.  Though I don't really get how to use the signal function.

I've tried some stuff but it doesn't work.

« Last Edit: June 16, 2010, 12:02:02 AM by Admin »
 
webmaster forum
sh4sh4  Offline
Activity
0%
 
New Poster
Posts: 8
Topics: 7
June 27, 2010, 06:00:39 PM

try system("pause");
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
July 06, 2010, 03:00:41 PM

Signals is probably the best option - basically the OS will send a signal (i.e. kill) to an application, you can catch this and deal with is appropriatly. When you do CTRL-C this sets off the KILL signal so by catching it you have in effect caught CTRL-C.

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
webmaster forum
singam  Offline
Activity
0%
 
Regular Coder
Posts: 50
Topics: 19
July 22, 2010, 12:51:37 AM

<html>
<head>
<script language="javascript">
function handleError(){
  try{
    document.writes("JavaScript Examples");
  }catch(exception){
    err=exception + "\n";
    err+=exception.description + " Error\n";
    err+="There is an error at this page.\n";
    err+="Click OK to continue viewing this page,\n";
    err+="or Cancel to return to the JavaScript Examples page.\n";
    if(!confirm(err)){
      document.location.href="http://www.TechnicalTalk.net/";
    }
  }
}
</script>
</head>
<body>
<input type="button" value="Click to Handle Errors" onclick="handleError()">
</body>
</html>
« Last Edit: March 17, 2011, 10:31:09 PM by Admin »
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
WWW
July 22, 2010, 04:47:23 AM

<html>
<head>
<script language="javascript">
function handleError(){
  try{
    document.writes("JavaScript Examples");
  }catch(exception){
    err=exception + "\n";
    err+=exception.description + " Error\n";
    err+="There is an error at this page.\n";
    err+="Click OK to continue viewing this page,\n";
    err+="or Cancel to return to the JavaScript Examples page.\n";
    if(!confirm(err)){
      document.location.href="http://www.TechnicalTalk.net/";
    }
  }
}
</script>
</head>
<body>
<input type="button" value="Click to Handle Errors" onclick="handleError()">
</body>
</html>


This code does not sound like catching the CTRL+C.

This code is for catching the exception and how one can use the exception object to display the error message. [Handling the exception]

Please read the thread carefully and then post your reply.
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
WWW
August 01, 2010, 06:05:56 AM

Did you ever get this working?

Mesham Type Oriented Parallel Programming Language, Free online technical support
 
webmaster forum
Activity
0%
 
New Coder
Posts: 20
Topics: 2
April 13, 2011, 02:17:34 PM

Signals is likely the best option - basically the OS will send a signal to an application, you can catch this and deal with is appropriatly.  When you do CTRL-C this sets off the KILL signal so by catching it you have in effect caught CTRL-C.

cabinet doors | games | de-duplication software
 
webmaster forum
Activity
0%
 
New Coder
Posts: 20
Topics: 2
April 13, 2011, 02:25:12 PM

Signals is probably the best option basically the OS will send a signal to an application, you can catch this as well as deal with is appropriatly.

cabinet doors | games | de-duplication software
 
webmaster forum
mak14317  Offline
Activity
0%
 
Skilled Coder
Real name: Janne
Location: california
Gender: Male
Age: 26
Posts: 108
Topics: 1
WWW
April 30, 2011, 02:22:27 AM

I thought it should be something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
   

#include <stdio.h>
#include <signal.h>

using namespace std;

int main(int argc, char *argv[])
{
    signal(SIGABRT,myFunction);//If program aborts go to assigned function "myFunction".
    signal(SIGTERM,myFunction);//If program terminates go to assigned function "myFunction".
//Or should I use signal(SIGNINT,myFunction)
}
void myFunction()
{
    cout<<"Program was trying to abort or terminate."
}
it will be like this.........

herbal vaporizer
Happy vappy vaporizer
Eclipse Vape
Ivape
 
webmaster forum
Radhaa  Offline
Activity
0%
 
New Poster
Posts: 5
Topics: 0
May 10, 2011, 02:45:53 AM

Hi all,

I want to catch the CTRL+C command and then let one of my own methods handle it.
Since CTRL+C terminates or aborts the program I thought I'd use the signal() function from the signal. h library.  Though I don't really get how to use the signal function.

I've tried some stuff but it doesn't work.  U try this

   
#include <stdio. h>
#include <signal. h>

using namespace std;

int main(int argc, char *argv[])
{
    signal(SIGABRT,myFunction);//If program aborts go to assigned function "myFunction".
    signal(SIGTERM,myFunction);//If program terminates go to assigned function "myFunction".
//Or should I use signal(SIGNINT,myFunction)
}
void myFunction()
{
    cout<<"Program was trying to abort or terminate. "
}

« Last Edit: May 10, 2011, 08:17:15 PM by Admin »
 
webmaster forum
msdnguide  Offline
Activity
0%
 
New Coder
Posts: 19
Topics: 1
WWW
May 27, 2011, 04:36:10 AM

catch SIGKILL (Signal 11) this will trap CTRL C

Visual Studio
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 01, 2012, 01:08:38 AM