proc connect {where} { global ssh set ssh [open "|ssh $where" "r+"] fconfigure $ssh -buffering line -blocking 1 puts $ssh { fconfigure stdout -buffering line while {![eof stdin]} { set cmd [gets stdin] set code [catch $cmd result opt] puts [string map [list \\ \\\\ \n \\n] $opt] puts [string map [list \\ \\\\ \n \\n] $result] } } return $ssh } proc remote {args} { global ssh #puts stderr "CMD: $args" puts $ssh $args set result "" set cnt 0 set opt [string map [list \\n \n \\\\ \\] [gets $ssh]] #puts "OPT: $opt" set result [string map [list \\n \n \\\\ \\] [gets $ssh]] #puts "RESULT: $result" return -options [eval dict create $opt] $result } if {[info exists argv0] && ($argv0 == [info script])} { connect snapshot@colin puts [remote set mumble 100] puts [remote incr mumble] puts [remote set mumble] puts [remote return "Woo\\nWoo\\n"] puts [remote set blerf] ;# expect an error here puts [remote set mumble] }