I can tell you a few things you probably already know:
The tcl part (ok, the expect part) runs well. The tk widgets are misbehaving.
Unfortunately, I'm not a big tk user. Here's a potential fix though:
Try redesigning the the gui in tkPROe (you can get it from sourceforge
http://tkproe.sourceforge.net/ )
Whenever I absolutely MUST have a widget, I use the ide and accept what it gives me.
Honestly, though, your task is REALLY simple in bash. I would do this:
Code:
ping -c 1 -w 4 $1 2> /dev/null; [ $? -eq 0 ]&& echo "Host $1 reachable." || "Host is unreachable;
or
Code:
#!/bin/bash
#this is slightly more sophisticated but it will also tell if you have an internal error.
# ping will return an error code of 0 on success or 2 if the host is unreachable
# $? queries the shell for the exit status of the last action (in this case ping)
ping -c 1 -w 4 $1 2> /dev/null
# send the ping. it might be better to use -c 3 or more instead of just 1 btw.
# 2> /dev/null redirects the error output so it looks clean on your screen
case in $?
0) echo "Host $1 is reachable."
;;
2) echo "Host $1 is unreachable."
;;
*) echo "ping failed with internal error."
;;
esac
you could then use the "add launcher" feature from your DE's panel to "add an empty item" and c/p the script into it.
Don't get me wrong, I absolutely love tcl, but you're making a molehill into a mountain.
in pure tcl, your script would be
Code:
#!/usr/bin/tclsh
#catch function will keep the program from halting if ping fails
#tcl global errorCode will hold an error vector (space delimited)
#element 2 of $errorCode is the bash exit code.
#
#ping normally exits with 2 if the host is unreachable.
#
#OK
#tested 20150902 POLARIS
if { ![catch { exec ping -c 1 -w 4 [lindex $argv 0]}]} {
puts "Host [lindex $argv 0] reachable."
} else {
if { [ lindex [ split $errorCode " " ] 2 ] == 2 } {
puts "Host [lindex $argv 0] is unreachable."
} else {
puts "ping failed with an internal error."
}
}
return 0
Best of Luck!