How to call on terminate function in perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cnsabar
    New Member
    • Dec 2007
    • 40

    How to call on terminate function in perl

    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.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by cnsabar
    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

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      I'm not sure how wise this is but using a simple example:

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

      Comment

      • cnsabar
        New Member
        • Dec 2007
        • 40

        #4
        Originally posted by KevinADC
        I'm not sure how wise this is but using a simple example:

        Code:
        local $SIG{INT} = sub { print "good-bye\n"; exit(0); };
        while (1){
        print "hello\n";
        sleep(2);
        }
        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,

        Comment

        • cnsabar
          New Member
          • Dec 2007
          • 40

          #5
          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.



          Originally posted by cnsabar
          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,

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            I don't know.

            Comment

            Working...