By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,850 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,850 IT Pros & Developers. It's quick & easy.

How to call on terminate function in perl

P: 40
Hi.,

I want to call some function when the user force to terminate the perl program.

For example.,
I write a program to create a file when the program starts...
Also I need to delete a file when the user force to terminate the process

i.e Calling some function when the user hitting Ctrl+C in perl command prompt..

Looking for Ur suggestions.

Thanks.
May 2 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Hi.,

I want to call some function when the user force to terminate the perl program.

For example.,
I write a program to create a file when the program starts...
Also I need to delete a file when the user force to terminate the process

i.e Calling some function when the user hitting Ctrl+C in perl command prompt..

Looking for Ur suggestions.

Thanks.
I think I know what you are asking to do, but I don't know if its possible or how to do it. Hopefully one our experts will have an answer for you.

Regards,

Jeff
May 6 '08 #2

KevinADC
Expert 2.5K+
P: 4,059
I'm not sure how wise this is but using a simple example:

Expand|Select|Wrap|Line Numbers
  1. local $SIG{INT} = sub { print "good-bye\n"; exit(0); };
  2. while (1){
  3. print "hello\n";
  4. sleep(2);
  5. }
  6.  
I would read up on signals more and see what the perl documentation has to suggest. A place to start:

http://perldoc.perl.org/perlipc.html
May 6 '08 #3

P: 40
I'm not sure how wise this is but using a simple example:

Expand|Select|Wrap|Line Numbers
  1. local $SIG{INT} = sub { print "good-bye\n"; exit(0); };
  2. while (1){
  3. print "hello\n";
  4. sleep(2);
  5. }
  6.  
I would read up on signals more and see what the perl documentation has to suggest. A place to start:

http://perldoc.perl.org/perlipc.html
Hi Kevin,

Thanks for your help and suggestion.,
Using the above logic,
Now I can able to produce the expected output in my program.

Thanks,
May 7 '08 #4

P: 40
By Using this function , its works fine when the I press Ctrl + C
But it wont reflect anything when I close the command prompt using close icon on the right corner of the window.



Hi Kevin,

Thanks for your help and suggestion.,
Using the above logic,
Now I can able to produce the expected output in my program.

Thanks,
May 24 '08 #5

KevinADC
Expert 2.5K+
P: 4,059
I don't know.
May 25 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.