Tcl Expect addition

I have been playing around in expect recently and I for the life of me can't figure out how to perform a simple addition on a variable I passed in. Anyone know how to do this? Also, is there a decent online reference for Expect? I have tried googling with very limited results.

Tcl How can I output a list of the values for all variables from the info globals command?

I am trying to write a small bit of code that will list all of the variables and the values they contain in the info globals command. I have tried several iterations of substitution but cant get Tcl to treat the variable name as a variable, and return its value. Below is what I started with: set fileid [open "c:/tcl variables.txt" w+] foreach {x} [lsort [info globals]] { set y $x puts $fileid "$x $y " } I can get DEG2RAD DEG2RAD PI PI RAD2DEG RAD2DEG ..... or D

Tcl parameter list clarification

I came across the following and cannot figure out what this parameter list means: proc IsSpecificationLive { specificationDate { onDate "" } } More specifically, what is the purpose of { onDate"" } being inside the parameter list?

Passing arguments in the command line in TCL

From the Tcl FAQ for Windows: To run a console script, invoke the tclsh.exe program, passing it the path to the script file. Any additional arguments on the command line are passed as a list to the script in the argv global variable # File printargs.tcl foreach arg $::argv {puts $arg} We can invoke this script from the command line: c:\> tclsh printargs.tcl first "second arg" first second arg c:\> I am able to do this. But how is this working? How the arguments are going?

Writing a tcl script using event_register_syslog

I am a newby to this but I am tasked at writing a tcl script. The script is to print a message on the command line "Warning, system error detected" when a syslog system_error is found. Now I am completely new to tcl and all I know is that an event_register_syslog needs to be used. Other than that I am completely in the dark and do not know where to go or start. There are no GUIs needed just the CLI. Any help and support would be much appreciated.

Tcl How to tokenize line, without a list into it?

How to tokenize line, without a list into it. For example for such lines: name name1 name2 name3 3.41 787.0 5.0 8.0 this regexp works great: set lst [regexp -all -inline {\S+} $line] But for such lines: name1 name2 { name1 name2 name3 } I would like to get list of the 3 items: name1 name2 { name1 name2 name3 }

Tcl How to declare optional arguments in proc

Could you help me how to use arguments with optionals I used this function but it does not work proc {my_proc} {n1 n2 -args{{u2 "5"} {u1 "5"}} } { puts "n1:'$n1', n2:'$n2', u1:'$u1', u2:'$u2'" } ->my_proc 1 -args 5 7 n1:'1', n2:'$n2', u1:'7', u2:'5' I would like to call function like my_proc 1 -args {u2 5} {u1 7} my_proc 1 {u2 5} {u1 7} (required + optional arguments) my_proc 1 (only required arguments)

How to interrupt Tcl_eval

I have a small shell application that embeds Tcl 8.4 to execute some set of Tcl code. The Tcl interpreter is initialized using Tcl_CreateInterp. Everything is very simple: user types Tcl command the command gets passed to Tcl_Eval for evaluation repeat Q: Is there any way to interrupt a very long Tcl_Eval command? I can process a 'Ctrl+C' signal, but how to interrupt Tcl_Eval?

Global variables in complex Tcl/Tk apps? Design patterns, conventions, style?

Whenever I write a Tcl/Tk app, I am plagued by the necessity to use global variables because callback scripts are evaluated in the top level scope, and I always want to use proc's for callbacks to hide the complexity. But I hate having globals in all my procedures... My way around this is to use a parameter for the name of a global variable and upvar to reference it, so at least I can see which global variable is being used (and modified) as part of the proc call. Often that is a single STATE

Is there a way to handle proc that does not exist in Tcl?

I am new to tcl. Is there a way we can handle the procs that does not exist though being called in the script. I am giving you the example Suppose this is our code package require 65ABC package provide package1 65ABC::callingFunction param1 param2 (# this does not exist in 65ABC) It will throw an error saying undefined command 65ABC::callingFunction If i remember correctly not sure about TCL but in other languages, in these cases there is a universal proc. It means in the above mentioned s

Creating a file in TCL on windows

It seems like this code should work... set data "sample text" set file_name "C:\Test2.txt" set file_obj [open $file_name w] puts -nonewline $file_obj $data close $file_obj But no file is created on either of my systems. set file_name "C:\Test2.txt" file exists $file_name Comes back as 1 (true) while the file does not exist whatsoever. Confusing.

Using a external variable in tcl

I have a script which generates a numbered file.. like this: set no 0 file fn [open log_file_$no w] I want to remember this no every time I run the script, i.e when running for the first time, the file name should be log_file_0 , 2nd time it should be log_file_1 etc. Is there a way to "remember" the value of the variable so that it can be used later?

In TCL what is the best way to add 2 very long string formatted hex numbers?

I need to add 2 very long string formatted hex numbers using TCL. If the strings were short, I could use something like this: set a "BEEF" set b "F00D" format "%X" [expr 0x$a+0x$b] But my hex strings are very long and the output of the last line above will result in "integer value too large to represent". I am thinking of writing my own proc to either add the digits one by one (while keeping track of the carry) or break the string in smaller chunks then sum and merge together. Are there any

Tcl linux - telnet - script with expect

I was writing an expect-script which communicate with a server via telnet, but right now i need to evaluate the reply from server. Usage: ./edit.expect EXPECT script: #!/usr/bin/expect<br> spawn telnet ip port expect "HUH?" send "login testuser pass\r" expect "good" send "select 1\r" expect "good" send "me\r" expect "nick=testuser id=ID group=testgroup login=testuser" send "edit id=ID group=3\r" expect "good" send "quit\r" If i send the command "me" i get a reply from the server whi

Tcl Error while selecting business object in eMatrix

I am trying to run this mql command on ennovia ematrix plm print bus type 'Own design item' name 'RAU1204038' revision * select *; but I am getting this error Error: #1900068: print business object failed Error: #1500029: No business object 'Error getting object name Own design item name' found System Error: #1500178: business type '0' does not exist

Tcl: Removing the pound sign commented line

Why can't I remove the pound sign commented line? #!/usr/bin/tclsh set lines [list file1.bmp { # file2.bmp} file3.bmp ] # Now we apply the substitution to get a subst-string that # will perform the computational parts of the conversion. set out [regsub -all -line {^\s*#.*$} $lines {}] puts $out Output: file1.bmp { # file2.bmp} file3.bmp -UPDATE- Expected output: file1.bmp {} file3.bmp {} means empty string. In fact, it's my first step. My ultimate goal is to eliminating all comm

Tcl Find a ip next line inside a while

Inside a "while" I need to verify if in a next line on lindex position 1 I have the same ip on this round. If yes, do something, if not do another thing. ips.txt 169.254.0.1,169.254.1.1 169.254.0.2,169.254.1.1 169.254.0.3,169.254.1.2 169.254.0.4,169.254.1.2 How can I do this with tcl? Thanks.

How to copy files within directory rather than a whole directory in TCL?

Because of software upgrade files are saved to a wrong directory and existing script does not work and I need to fix it. Files are saved few folders deeper in the project file. I know I can use this command to copy directories file copy -force "path_files_to_copy" "path_to_copied_into" This way though it will copy the folder, the path is pointing to rather than the each individual folder and file within that folder. How do I copy everything within a specified path to a new location rather tha

Tcl Radial density distribution on a MD trajectory

I have a molecular dynamics trajectory of a micelle in a water box. For each frame, I want to get center of mass (COM) of the micelle and calculate the density of water molecules from COM to the sides of the water box. Does anybody know what is the best way to do that? I was wondering whether somebody has dealt with such an issue before. Thanks Sadegh

Tcl Count number of words of specific type

I have a file having following data Anny : dancing Sonny : reciting Joel : dancing Anny : reciting Anny : singing I want the following o/p in tcl: Anny - singing 1 dancing 1 reciting 1 Joel - dancing 1 I want to print in this format along with their count.

Tcl Get attributes of an Agent in NS2

I actually need to know the attributes of my UDP Agent in my TCL script (to print some values and use it for statistics) and this is my first time with this script language. I tried to use the command info but I failed to use it. This is my code : #Setup a UDP connection set udp [new Agent/UDP] puts [$udp info class] # Work and print "Agent/UDP" puts [info class variables Agent/UDP] #Fail with the error "Agent/UDP does not refer to an object" I tried with : puts [info class variables udp]

How to show a directory structure(explorer) in tcl tk?

I am not able to add nodes recursively in a treectrl. i.e. I want to show all the directories and files as in an explorer. Till now, this is what I have. I am adding dummy nodes in each folder currently. package require treectrl treectrl .t -showheader 0 -selectmode single -showroot 0 -yscrollcommand {.y set} scrollbar .y -ori vert -command ".t yview" pack .y -side right -fill y pack .t -side right -fill both -expand 1 set columnID [.t column create -text "Column 0"] .t configure -treecolu

SWIG tcl : undefined symbol error for log4cpp wrapper

I am new in log4cpp and swig wrapper. I am trying to write an interface for simple logging using log4cpp. I have installed log4cpp and swig in my Ubuntu machine. log4cpp.cpp: #include "log4cpp/Category.hh" #include "log4cpp/Appender.hh" #include "log4cpp/FileAppender.hh" #include "log4cpp/OstreamAppender.hh" #include "log4cpp/Layout.hh" #include "log4cpp/BasicLayout.hh" #include "log4cpp/Priority.hh" #include "log4cpp.h" void writeLog() { log4cpp::A

Tcl how to make a camera in tk?

I have a grid based coordinate system where the distance between each grid center is a set number of pixels. Doing this in OpenGL I made a camera using view/projection matrices. Changing view center and scale for the whole scene could be made by setting matrix elements. This is from a prototype using OpenGL that I made before going full Tcl/Tk. The node positions are {[1..5], [1..3]} (text at fractional y-offset): How would I accomplish this in Tcl/Tk? I'm reading about canvas zooming howeve

Tcl Binary format issue when writing to file

Below there is a trivial script writing a byte to a file: set wf [open "test.bin" "w"] set int_result 0x80 puts -nonewline $wf [binary format c [expr {$int_result}]] close $wf exit Surprisingly, the file will contain 0x3F, not 0x80. Can anybody explain what is happening? Thanks a lot, Dmitry

Tcl How to copy or move multiple files with same extension?

So I am trying to move a bunch of files with similar extensions from /home/ to /root/ Code I tried is file copy /home/*.abc.xyz /root/ Also tried set infile [glob -nocomplain /home/*.abc.xyz ] if { [llength $infile] > 0 } { file copy $infile /root/ } No success.

How to get name of TCL test from the test itself

I was wondering how you would find the name of the test you're running in tcl from the test itself? I couldn't find this on google. I'm calling another proc and passing the name of the test that is calling it, as an argument. So I would like to know which tcl command can do that for me.

Tcl Remove characters at end of each element

I have a problem with removing characters in TCL. I have a variable that contains 3 elements: > puts $scan_ports scan_clkvco_clk scan_clkvco_div_2_clk scan_clkin_clk And I would like to save in another variable, those same 3 elements, but removing the _clk at the end of each element. This is what I have tried: regsub -all "_clk" $scan_ports "" scan_groups But it removes all _clk matches The expected result should be: puts $scan_groups > scan_clkvco scan_clkvco_div_2 scan_clkin

How do I define a text area using sed and printf in tcl

Hi im try to add a definded text area %-74s using sed and printf in a tcl script i have but im not sure how to add the printf info to the line of code i have puts $f "sed -i "s/XXXTLEXXX/\$1/\" /$file"; any help would be greatly appreciated ive tried a few combinations but all error

Tcl read register value into variable - e.g. control location of pc

Aim is to check if my controller has halted at the correct position. I'm using tcl-script. The commend reg pc outputs the value of the register pc to the console. So in theory following command should store something in a variable. set x [ reg pc ] But the resulting variable xremains empty. How can I retrieve the value of a register and store it into a variable?

Tcl how can set to variable from expect

I want to start the python script with the tcl script and wait for the python script to finish. At the end of the Python script there is an edition and I would like to capture it. The output from test.py is as an example: done testdir1 testdir2 testdir3 I would like to put testdir3 in a variable. bind pub "-|-" !dir pub:dir proc pub:dir {nick host handle channel arg} { spawn python test.py expect "done" {putnow "PRIVMSG $channel :match"} putnow "P

Tcl embedded Tk - hangs on ctrl+d

Our application has tcl embedded in it and by usingstarkit; tk is statically linked into it. When I run the application, gui comes up and responds to all keys but when I hit ctrl+d to terminate it hangs. I have given the back trace of the hang at the end of the post. First let me describe how we are embedding Tcl/Tk in our application. #-------------------------------------------------------------- # (*) install ActiveTcl # we need starkit and ActiveTcl tclsh is batteries included #--------

Tcl Scrolling canvas

This is probably something really basic as a tcl/tk newbie, but I've spent all day on it and have no idea where I'm going wrong: I'm teaching myself from a mix of code I've been given (which probably isn't very well written), and the main tcl/tk resource site, so probably not picking up the best practices! I have a single frame containing a single canvas, with a scrollbar. #!/usr/bin/env wish frame .f -bg blue canvas .f.c1 -bg red -scrollregion "-1000 -1000 -1000 1000" \ -yscrollco

Tcl How to use two $ for creating new variable

I have my tcl code like below, set n0 [$ns node] $n0 set X_ 284 $n0 set Y_ 380 $n0 set Z_ 0.0 $ns initial_node_pos $n0 20 set n1 [$ns node] $n1 set X_ 343 $n1 set Y_ 195 $n1 set Z_ 0.0 $ns initial_node_pos $n1 20 Then I added for{ } loop to assign TCP connection for every node: for {set i 0} { $i < 10} {incr i} { set tcp1 [new Agent/TCP] $ns attach-agent $n$i $tcp1 } It shows the error like, can't read "n": no such variable while executing "$ns attach-agent $n$i $tcp1"

Tcl what are the elements to feed join command?

I am confused at "join" command, here is my code inside tclsh: % lappend aaa 1 1 % lappend aaa 2 1 2 % lappend aaa {3 4} 1 2 {3 4} % join $aaa 1 2 3 4 so the list aaa should have 3 elements: 1, 2 and {3 4}. Because "join" command should just concat all the elements together to form a string, then the return should be "1 2 {3 4}" because the list has just 3 elements. Why does join command break the 3rd element?

TCL open file and check for error

I am programming TCL for Cisco TCL/IVR inside voice gateway. I have some text files with public holidays dates, which I need to open on the primary server. If an error is returned while opening the file, I want to try to use a secondary backup server. code: if [catch {set fd [open $filename] } errmsg] { error "Unable to open the file: $filename on Primary Server \n $errmsg" set filename $httpsvr2$textfile if [catch {set fd [open $filename] } errmsg] { error "Unable to open

Tcl How to spawn from a variable in Expect

There are processes that take in a password partway through computation. I wish to insert a password at the start of the process, so I am trying to create a generic expect script that will spawn a process, then give it a password. This expect script takes in the password to enter and the process to spawn: #!/usr/bin/expect set timeout 120 # Get program to spawn and password to send set pswd [lindex $argv 0] set program [lindex $argv 1] spawn $program expect "Password:" send "$pswd\r" inte

Tcl/Tk : embed expect send script inside wish script

I have a wish script which will do spawn, expect and send and get the required data. When I run the script as wish ex.tcl, its not working. Please find the code below for more information. #!/usr/bin/wish package require Expect proc openSession { targetHost } { log_user 1 set user $::env(USER) set password "tmp1234" set timeout 60 set spawn_id "" puts "Ssh to $user@$targetHost" spawn ssh -o UserKnownHostsFile=/dev/null $user@$targetHost match_max -i $spawn_i

How to use the left and right arrow keys in the tclsh interactive shell (Ubuntu 14.04)?

Why can't I use the left and right arrow keys (actually, the same goes for the up and down keys as well) to move about the line I'm currently on in the tclsh interactive shell? If I try to press either one, I get a bunch of abracadabra instead of moving back and forth. This is not all that convenient when, for example, you make a typo, but you can't move the cursor back to change it. You have to use the backspace key to erase all the stuff that you've typed after the place where the typo is loca

Tcl how to get the value from ttk:entry

I am trying to get the value from ttk:entry. I have the following code. variable DefaultRoot ttk::label $wi.custcfg.dlabel -text "Default Root:" ttk::entry $wi.custcfg.daddr -width 10 -textvariable ::DefaultRoot -validate focusout -validatecommand { puts $::DefaultRoot; return 1} puts $DefaultRoot But I am getting error on the last puts

Tcl How to find duplicated strings which appear more than once in a file

I have following code to print string which appears more than once in the list set a [list str1/str2 str3/str4 str3/str4 str5/str6] foreach x $a { set search_return [lsearch -all $a $x] if {[llength $search_return] > 1} { puts "search_return : $search_return" } } I need to print str3/str4 which appears more than once in the list

Tcl how to run expect script on a given spawn id

How to run bunch of expect scripts on spawnid from first expect script Here are the details: I have first expect script that shall spawn a application called openapp. Now i want to run tests(written in expect scripts - abc), that will do different validations on the spawned application id #!/usr/bin/expect -f source home/tests/library.tcl set openapp [runapp] eval spawn $openapp set id $spawn_id login puts [exec home/tests/testsuite/abc $id] expect eof #!/usr/bin/expect -f sourcehome/tests/

Tcl How to "gray out" or disable tabs in ttkNotebook?

I am going through the ttk notebook manual found here, but I cannot seem to find something that would do the affect stated in the title. The closest thing I see is the hide tab option, but I would like for it to be disabled instead of hidden. Is there a way to achieve in this in tcl/tk, specifically in an R setting?

Why doesn't doxygen recognise comments in .tcl?

I got stuck with doxywizard, as it fails to recognise any comment, even on easier files. I have Doxygen 1.8.18, which is the last doxygen version that supports TCL (according to this site). I saved the code example from the previously mentioned site. I left most of the configuration as default, except: unchecked latex output under Expert>Build checked EXTRACT_ALL under Expert>Input changed FILE_PATTERNS to *.tcl only The output generates docs for the tclexample.tcl file, which is even pr

  1    2   3   4   5   6  ... 下一页 最后一页 共 13 页