Posted to tcl by aspect at Fri Jul 30 05:07:50 GMT 2010view pretty
#!/usr/bin/tclsh # save as test.tcl # run with same arguments as telnet # see expect manual for expect_after, timeout, log_user, interact package require Expect set timeout 2 expect_after timeout { puts "Expect timed out!" exit -1 } log_user 0 puts -nonewline "Connecting to $argv: " # tcl8.6: spawn telnet {*}$argv eval spawn telnet $argv expect { Connected { puts "Connected" log_user 1 interact } "Connection refused" { puts "Error connecting!" exit -2 } } puts "Disconnected"