Re: exception handling for control C

From: TCMa (ma77777777772000_at_yahoo.ca)
Date: 12/18/03


Date: 17 Dec 2003 17:14:38 -0800

How to mask signal inside the expect signal handler?
If the INT signal is masked inside the expect signal handler SIGINT ,
then the program should work.

> Don Libes <libes@nist.gov> wrote in message news:<s6ad6aoe03i.fsf@peace.mel.nist.gov>...
> > Well, at this point, it's just a matter of getting your logic right.
> > Why don't you have GetResponse check traped before (as well as after)
> > it calls gets?
> >
> > Don
> >
> >
> > ma7777772@hotmail.com (TingChong) writes:
> >
> > > How to call a function inside an signal handler when the main program
> > > also calls that function which also encounters the same signal?
> > >
> > > e.g.
> > > trap {
> > > global traped
> > >
> > > set traped 1
> > > puts "Would you like to exit (y/n)?"
> > > set resp [GetResponse {"yn" ""}]
> > > if {$resp == "y"]} {
> > > puts "exit"
> > > exit 1
> > > }
> puts "program resume..."
> > > } SIGINT
> > >
> > > proc GetResponse {validChar {defaultChar ""} errorMessage} {
> > > global traped
> > >
> > > set pattern \[[string tolower $validChar]]
> > > while {1} {
> > > #ensure response has a valid value if exception occurs
> > > catch {gets stdin} response
> > > puts "traped $traped"
> > > if {$traped == 1} {
> > > set traped 0
> > > puts "$errorMessage"
> > > continue
> > > }
> > > puts "response $response"
> > > set response [string tolower [string trim $response]]
> > > if {$response eq ""} {
> > > set response $defaultChar
> > > break
> > > }
> > > set firstChar [string index $response 0]
> > > if {[string match $pattern $firstChar]} {
> > > set response $firstChar
> > > break
> > > }
> > > puts "Invalid input '$response'."
> > > puts "$errorMessage"
> > > }
> return $response
> > > }
> > >
> > > set i 0;
> > > while {1} {
> > > puts "Please insert a tape and press <Enter> to continue or \"e\" to
> > > exit."
> > > set resp [GetResponse "e" "" "Press <Enter> to continue or \"e\" to
> > > exit."]
> > > if {[string match $resp "e"]} {
> > > exit 0
> > > }
> > >
> > > puts [incr i]; after 20
> > > }
> > >
> > > # the output is:
> > > Please insert a tape and press <Enter> to continue or "e" to exit.
> > > ^CWould you like to exit (y/n)?
> > > traped 1
> > > Press <Enter> to continue or "e" to exit.
> > >
> > > ----------------------------------------
> > > The user do not have a chance to enter "y" or "n" after the "control
> > > C" is pressed at the prompt "Please insert a tape and press <Enter> to
> > > continue or "e" to exit.".
> > > How to fix that?
> > > Please help.
> > >
> > > Don Libes <libes@nist.gov> wrote in message news:<s6afzfpexbu.fsf@peace.mel.nist.gov>...
> > > > Have the signal handler set a global variable. Then check the
> > > > variable after returning from the gets to figure out whether it
> > > > returned normally or due to the signal handler. Then you can decide
> > > > whether to retry the gets or not.
> > > >
> > > > Don