tcl

How to handle tcl expect output

*爱你&永不变心* 提交于 2019-12-24 13:39:27
问题 I am writing an expect script to telnet to the router ,do some config,expect some output. If the required prompt is not available then it waits for it and gets time out. So how do i have to handle this and print an error msg. set timeout 30; puts "Telnet to $IP 2361\n\n"; spawn telnet $IP 2361; expect ">"; send "ACT-USER::$user_name:1::$password;"; expect ">"; How do i handle and print an error msg if the expected value is not received? 回答1: Dealing with timeouts nicely requires a slightly

Decent interactive TCL shell

China☆狼群 提交于 2019-12-24 13:13:59
问题 Is there anything like the iPython notebook for TCL? Or at the very least, a shell that lets me use ctrl-f, ctrl-b, ctrl-a etc. without filling the shell with ^B etc. 回答1: Have a look at tkcon I like rlwrap tclsh -- see if your OS's package repository has it, or get it from github 来源: https://stackoverflow.com/questions/29743621/decent-interactive-tcl-shell

Expect Procedure for SSH Login

心不动则不痛 提交于 2019-12-24 12:06:35
问题 I'm new to Expect scripting. I'm trying to create a procedure that will connect to routers/switches over SSH and fall back to telnet if that fails. The code that I have works fine before I put it inside a procedure. I'm sure there's something I'm not understanding about how procedures work. When I call it as a procedure it does connect via SSH which receives "Connection refused" and falls back to telnet like it is supposed to, it just never logs in with the password. When I enable debug mode

TCL / Expect Scripting - Using a conditional statement to attempt a secondary login password

陌路散爱 提交于 2019-12-24 08:55:46
问题 I am very close to finish a TCL/TK app that logs into a Cisco Access Point via a serial connection (RS232} and gives it an IP address (very basic) However, I would like my script to attempt a secondary password if the first one fails This is how the Cisco CLI behaves with a serial connection when the incorrect password is entered 3 times (No User Name is needed, only prompts for a password) Password: Password: Password: % Bad secrets Again, if the default password of "Cisco" does not work, I

How to use foreach for using regexp

天涯浪子 提交于 2019-12-24 08:39:27
问题 I am using the following code to search for a particular data and store it in a variable. foreach searched $names { [regexp {[cell]+} $searched match] } Here names is the variable which has many data. I am getting an error saying: Error: invalid command name "1. I am new to tcl so I cant figure out whats wrong. Is my code correct, will it work? Thanks 回答1: Your regexp is evaluating first and regexp {[cell]+} $searched match returns 1 , which then becomes: [1] Which is an invalid command.

How to make the text in a Tk label selectable?

与世无争的帅哥 提交于 2019-12-24 08:28:47
问题 I'm creating labels in Tcl Tk, but their text is not selectable (for copy-paste). How do I make is selectable? I crate the labels using: set n 0 foreach t $list_of_labels { incrr n set lbl2 [label .prop_menu.main_frame.val_$n -text $t] grid $lbl2 ... } 回答1: You can't without taking a lot of the binding code from some other widget and applying it to your label. If you need this, you would be better taking an entry widget and making it look like a label. Something like: entry .e1 -textvar t

Problem creating new command in `array` ensemble

笑着哭i 提交于 2019-12-24 08:00:06
问题 I want to create a convenience command array values arrayName as a "flip side" to the "array names" command. It's straightforward to create a simple proc: proc array_values {arrayName} { upvar 1 $arrayName ary set values {} foreach {name value} [array get ary] {lappend values $value} return $values } array set a {foo bar baz qux} puts [array_values a] ;# => bar qux However, I'm having difficulty creating a command in the ::tcl::array namespace: first some homework: is array a namespace

How to get the number of parameters that procedure accepts?

江枫思渺然 提交于 2019-12-24 07:40:50
问题 Is there a way in TCL to get the number of parameters that procedure accepts? For example we have procedure: proc func {a} { puts $a } I need a way to put in variable the number of parameters that func procedure accepts. 回答1: You could maybe try something like: info args func This will get the arguments that func require. Then you can use it to get the number of arguments: set num [llength [info args func]] In your case, $num will be 1. 来源: https://stackoverflow.com/questions/22932996/how-to

ns2 cannot connect to existing nam instance

旧城冷巷雨未停 提交于 2019-12-24 07:37:13
问题 I'm trying to run the below code using nam. set ns [new Simulator] set nf [open lab1.nam w] $ns namtrace-all $nf set f [open lab1.tr w] proc record {} { global sink f set ns [Simulator instance] set time 0.12 set bw [$sink set bytes_] set now [$ns now] puts $f "$now [expr (($bw/$time)*8/1000000)]" $sink set bytes_ 0 $ns at [expr $now+$time] "record" } proc finish {} { global ns nf f $ns flush-trace close $nf close $f exit 0 } set n0 [$ns node] set n1 [$ns node] $ns duplex-link $n0 $n1 4Mb

how to do getpwnam/getpwuid etc in tcl

て烟熏妆下的殇ゞ 提交于 2019-12-24 07:03:11
问题 does tcl have a standard way of doing NSS lookups (getpwnam, setpwent,...) 回答1: Tcl doesn't expose those as APIs (it doesn't really use them internally either) but the TclX extension package does support exactly what you want I believe. For example: package require TclX set uid [id convert user $tcl_platform(user)] puts "Your userid is $uid and you are a member of these groups: [id groups]" If you're using ActiveTcl, you've definitely got the TclX package available (either already installed