Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Messages Closing tcl App

Status
Not open for further replies.

dcomit

Technical User
Jun 20, 2001
115
GB
I have a tcl program running in Dos. I’m using a piece of software called FireDaemon which allows you to run any dos/Windows app as a service. Problem is that even though I’m running the service as a different user, as soon as I log myself off, the tcl app closes. FireDaemon restarts it ok but the shutdown is not clean and this may result in lost data.

I’m told that when you logoff Windows WM_CLOSE and WM_ENDSESSION messages are sent to all top level windows. So it looks like this is closing my tcl app. Is there an application switch in tcl to ignore these messages?
 
Any chance of putting a simple Expect wrapper around your tcl code and trapping the interrupt in there?
 
I'm not familiar with Expect but I can load it in tcl using package require. Could you expand a bit on how I would use it in this example?
 
I just tried surfing around for examples of interrupt handlers in expect. Can't find any. I've written them before in perl and was (falsely?) believing that expect could trap interrupts as well. If expect can trap them, it would probably have to be the outer layer program and not a 'require' into tcl, otherwise tcl would try to deal with the interrupt before passing it onto a subroutine. Sorry if this is too simplistic but the basic idea in perl would look something like:
Code:
$SIG{'QUIT'} = 'interrupt_handler';
$SIG{'HUP' } = 'interrupt_handler';
$SIG{'TRAP'} = 'interrupt_handler';
$SIG{'ABRT'} = 'interrupt_handler';
$SIG{'STOP'} = 'interrupt_handler';
sub interrupt_handler {
   my($signal)=@_;
   # if here, an interrupt was attempted - ignoring
   # You need to reset the sub call into the %SIG var
   $SIG{'QUIT'} = 'interrupt_handler';
   $SIG{'HUP' } = 'interrupt_handler';
   $SIG{'TRAP'} = 'interrupt_handler';
   $SIG{'ABRT'} = 'interrupt_handler';
   $SIG{'STOP'} = 'interrupt_handler';
   return 1 ;
   # If you want to exit, use this versus the 'return'
   # statement.
   # exit(1);
}

Sorry for the time waste if this is of no use. I found references to a tcl.trap command in some other postings but couldn't figure out how to get it to work.
 
Might have to do the job in Perl then. Thanks for trying anyway.
 
FWIW - Here is a fairly unsophisticated way I've used to get out of routines that I've disabled the interrupts
Code:
sub interrupt_handler {
   my($signal)=@_;
   if (-f $some_file_path) {
      &delete_file($some_file_path) ;
      exit 0
   }
   &reset_SIG();
   return 1 
}
I'm just giving the interpreter a chance to do it's thing and exit a little more cleanly. Just interpret the &delete_file and &reset_SIG in context as to what you might anticipate they're doing at that point. If you're in a *nix system and you override enough of the %SIG values, getting that program to stop can be it's own issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top