I have a small shell application that embeds Tcl to execute some set of Tcl code. The Tcl interpreter is initialized using Tcl_CreateInterp. Everything is very simple:
- user types Tcl command
- the command gets passed to Tcl_Eval for evaluation
- repeat
But if a user types ‘exit’, which is a valid Tcl command, the whole thing – Tcl interpreter and my shell application – exit automatically.
Q: is there any way I can catch this exit signal coming from Tcl interpreter. I really would like not to check every user command. I tried Tcl_CreateExitHandler, but it didn’t work.
Thanks so much.
Using
Tcl_CreateExitHandlerworks fine. The problem was that I added aprintfinto the handler implementation and the output didn’t show up on the terminal. So I thought it hasn’t been called. However, by the time this handler is executed there is nostdoutany more. Runningstraceon the application shows that the handler is being executed fine.Another solution to this problem can be to use atexit and process the exit event there.