handling errors in expect 
Author Message
 handling errors in expect

I'm writing an expect script that logs into an ftp site and downloads a
file.
Sometimes an error happens during the ftp session, and I want to send
myself an email if that happens. So what I need is a way to put an error
handler around the part of the expect script that opens the ftp session.
How do make such an error handler?

--
To reply to me directly, please remove "ANTISPAM" from the reply-to
email address.



Tue, 04 Apr 2006 05:18:54 GMT  
 handling errors in expect

Quote:

>I'm writing an expect script that logs into an ftp site and downloads a
>file.
>Sometimes an error happens during the ftp session, and I want to send
>myself an email if that happens. So what I need is a way to put an error
>handler around the part of the expect script that opens the ftp session.
>How do make such an error handler?

Something like this:

    if {[catch {
        if {$::tcl_platform(platform) eq "windows"} {
            spawn telnet
            expect "Microsoft Telnet> "
            send "set LOCAL_ECHO\r"   ;# force local echo on
            send "open $host $port\r"
        } else {
            spawn telnet $host $port
        }
    } err]} {
        send_error "Dying! Can't spawn telnet: $err\n"
        send_error "errorCode: $::errorCode\n"
        return -code error
    }

or

    if {[catch {
        while {1} {
            expect timeout {
                error "failed to contact weather server (timeout)\n"
            } "Press Return to continue*" {
               # this prompt used sometimes, eg, upon opening connection
               send "\r"
            } "Press Return for menu*" {
               # this prompt used sometimes, eg, upon opening connection
               send "\r"
            } "M to display main menu*" {
                # sometimes ask this if there is a weather watch in effect
                send "M\r"
            } "Change scrolling to screen*Selection:" {
                break
            } eof {
                error "failed to telnet to weather server (eof)\n"
            }
        }
    } err]} {
        send_error $err
        email_me "'$err' happened in [info script]! Die! Die!"
        exit 1
    }
--

[species: human; planet: earth,milkyway(western spiral arm),alpha sector]



Tue, 04 Apr 2006 06:20:57 GMT  
 handling errors in expect


Quote:

>>I'm writing an expect script that logs into an ftp site and downloads a
>>file.
>>Sometimes an error happens during the ftp session, and I want to send
>>myself an email if that happens. So what I need is a way to put an error
>>handler around the part of the expect script that opens the ftp session.
>>How do make such an error handler?

>Something like this:

>    if {[catch {
>    if {$::tcl_platform(platform) eq "windows"} {
>        spawn telnet
>        expect "Microsoft Telnet> "
>        send "set LOCAL_ECHO\r"   ;# force local echo on
>        send "open $host $port\r"
>    } else {
>        spawn telnet $host $port
>    }
>    } err]} {
>    send_error "Dying! Can't spawn telnet: $err\n"
>    send_error "errorCode: $::errorCode\n"
>    return -code error
>    }

>or

>    if {[catch {
>    while {1} {
>        expect timeout {
>            error "failed to contact weather server (timeout)\n"
>        } "Press Return to continue*" {
>           # this prompt used sometimes, eg, upon opening connection
>           send "\r"
>        } "Press Return for menu*" {
>           # this prompt used sometimes, eg, upon opening connection
>           send "\r"
>        } "M to display main menu*" {
>            # sometimes ask this if there is a weather watch in effect
>            send "M\r"
>        } "Change scrolling to screen*Selection:" {
>            break
>        } eof {
>            error "failed to telnet to weather server (eof)\n"
>        }
>    }
>    } err]} {
>    send_error $err
>    email_me "'$err' happened in [info script]! Die! Die!"
>    exit 1
>    }

                        .
                        .
                        .
I know this is what Daniel said he wanted, but I'll bet there
are at least a couple of mistakes, or at least misunderstandings,
afoot.

My own choice, fond though I am of Expect, is to abandon it
entirely for jobs such as this, and instead use tcllib's ftp
package <URL: http://wiki.tcl.tk/ftp >.  My guess is that Daniel
will understand its exception-handling more easily.

--


Business:  http://www.Phaseit.net



Tue, 04 Apr 2006 10:13:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Expect Telnet Error Handle?

2. Calling an external prog - timeout and error-handling in Expect

3. expect script and error handling

4. expect: bgerror failed to handle background error.

5. Error handling - Expect under Windows

6. handling errors from spawn'ed commands in Expect

7. expect ftp error handling

8. Expect spawn error handling

9. C5PE Compile Error: err.$$$(1) #6: Error: cif$filewrite The handle is invalid

10. error handling using CALL on error name ErrorRtn

11. Expect: error with puts after expect

12. EXPECT EXCEPTION ERROR - slavedrv.exe Application error

 

 
Powered by phpBB® Forum Software