stefan <
stefan....@wu.ac.at> writes:
>> Is this the best way to check if a command executed successfully?
>
> set fh [open |[list ping -c 1
example.org]]
> if {[catch {close $fh} e opts]} {
> lassign [dict get $opts -errorcode] msg pid exitcode
> puts $msg
> puts $pid
> puts $exitcode
> }
>
> open/close will give you access to the child process' details. You can
> then watch out for CHILDSTATUS, CHILDKILLED & friends.
That does not seem to work. (See my other reply.) But I used to better
some things.
I now initialise the following:
set cmd [list exec ping -c 1 -W 1 ${pingDomain} >/dev/null]
set intervalCheck 1
set notConnected "ping: ${pingDomain}: Temporary failure in name resolution"
And have the following proc defined:
proc checkInternetConnection {} {
if {[catch ${::cmd} errorStr opts]} {
if {${errorStr} == ${::notConnected}} {
set message "NOT connected"
} else {
set message "OTHER ERROR: ${errorStr}"
}
} else {
set message Connected
}
showMessage ${message} True
after [getWaitMinutesTicks ${::intervalCheck}] checkInternetConnection
}
showMessage is to show a message. For example:
13:35:00: Connected
13:36:40: NOT connected
13:37:40: NOT connected
13:38:00: Connected
And I use:
after [getWaitMinutesTicks ${::intervalCheck}] checkInternetConnection
To make sure that the check is run at the start of every minute.