f

#### [Tcl] How to do "command with timeout"?

Ok, an example:

set fail [catch {gets stdin} result]

if { $fail } { if {$result == "interrupted" } {
...
}
}

It passed thru the condition, because in 10 seconds the used did not enter
anything. How to program such a behavior?

I tried with enclosing it in a procedure (should be level #1 then) and I used
"after 10000 uplevel #1 return". However this script was invalid - despite
that the code actually executed was level #1, the "after" command (after 10000
ms of course) reported that #1 is invalid level.

Does anyone know any other way to program "break on timeout" for a command in
Tcl? I've found nothing on wiki.tcl.tk for 'timeout' keyword.

--
//  _    ___         Michal "Sektor" Malecki <sektor(whirl)kis.p.lodz.pl>
\\ L_ |/ |  /^\ ,()                         <ethourhs(O)wp.pl>
// \_ |\  \/ \_/ /\ C++ bez cholesterolu: http://www.intercon.pl/~sektor/cbx
"Java does not have pointers!"

 0
1/18/2005 11:49:10 AM
comp.lang.tcl 23429 articles. 2 followers.

1 Replies
377 Views

Similar Articles

[PageSpeed] 38

* Sektor van Skijlen <ethouris@pl.spamu.lubie.nie.wp.invalid>
| It passed thru the condition, because in 10 seconds the used did not
| enter anything. How to program such a behavior?

You need to avoid TCL getting blocked in an I/O operation.  I suggest
to set up a fileevent for the channel in question, which calls some
input-handler-function when input arrives.  Then set up the timeout
via after', and cancel that timer in the input-handler.

Schematically:

proc timeout {} {
puts stderr timeout
exit 1
}
proc handle_input {} {
after cancel $::after_id read stdin line # process input in$line
}

set after_id [after 10000 timeout]
fconfigure stdin -blocking 0 -buffering line

The wiki at http://mini.net/tcl also has plenty of information.

R'

 0
ralfixx (1283)
1/18/2005 12:41:46 PM

Similar Artilces:

tcl command "type"
Hello i am under windows xp family and Tcl/Tk 8.4 in the book "SAMS teach yourself Tcl/Tk" isbn 0-672-31749-4 page 154 listing 9.6 i find the following code source myfile.tcl type myfile.tcl when i code it i obtain the following error invalid command name "type" in the man pages "http://www.tcl.tk/man/tcl8.4/TclCmd/" if cannot find this command. my question is: if after having source any myfile.tcl i want to print it in the console is there a command to do it ? many thanks in advance for helping and explaining. Jerome suchodj@wanadoo.fr wrote: > Hello > i am under windows xp family and Tcl/Tk 8.4 > > in the book "SAMS teach yourself Tcl/Tk" isbn 0-672-31749-4 > page 154 listing 9.6 i find the following code > > source myfile.tcl > type myfile.tcl > > when i code it i obtain the following error > > invalid command name "type" > > in the man pages "http://www.tcl.tk/man/tcl8.4/TclCmd/" if cannot find > this command. > > my question is: if after having source any myfile.tcl i want to > print it in the console is there a command to do it ? No, there is not. There are a myriad of ways to do this, though I'm puzzled why you would need to. You can simply open the file up with your editor of choice. If you really want the contents dumped to the screen, you can read it in and print it out. Perhaps the SAMS book has you write a procedure to d...

Tcl "source" command
I'm trying to have two programs interact. One is a compiled FOrtran code and the other is a Tcl/Tk script. I have the Fortran code write a snip of Tcl I wish the script to "source" to effectively do what the code is saying to do. I think I am getting hung up with WHEN the "source" is happening. If I have, as I do, other instances of a file being sourced that occurs when a button is pressed, that "source" is apparently hidden from being done as the program starts. The "source" I am trying to do in an "if" block (determining whether the file to be sourced exists or not) happens "right now" and, as the file that needs to be sourced does not exist, the script fails. I need a way to "conditionally" execute the "source" command without the "source .." having to be associated with a button. There must be a way to do this. Bruce Graham wrote: > I'm trying to have two programs interact. One is a compiled FOrtran > code and the other is a Tcl/Tk script. I have the Fortran code write a > snip of Tcl I wish the script to "source" to effectively do what the > code is saying to do. I think I am getting hung up with WHEN the > "source" is happening. If I have, as I do, other instances of a file > being sourced that occurs when a button is pressed, that "source" is > apparently hidden from being done as the progra...

Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

TCL "unknown" command does not work...
Hello, I have done my own application. This application embeds a TCL interpreter (tcl8.4). I have a little issue with the "unknown" command: when I type "unknown ls" in my TCL interpreter I have the following message : invalid command name "ls" But when I type "unknown ls" in tclsh, the bash ls command is executed. I want to have the same behaviour than tclsh. Does anyone know what I am missing here ? Fabrice fabrice.dufour@gmail.com wrote: > I have done my own application. This application embeds a TCL > interpreter (tcl8.4). I have a little issue with the "unknown" command: > > when I type "unknown ls" in my TCL interpreter I have the following > message : > invalid command name "ls" > But when I type "unknown ls" in tclsh, the bash ls command is executed. > > I want to have the same behaviour than tclsh. Does anyone know what I > am missing here ? Check the value of $::tcl_interactive in the two cases you describe. -- | Don Porter Mathematical and Computational Sciences Division | | donald.porter@nist.gov Information Technology Laboratory | | http://math.nist.gov/~DPorter/ NIST | |______________________________________________________________________| Ok, thanks for the rapid answer ! It solves the problems. In tclsh, tcl_interactive is set to 1, whereas in my app it is simply not set ! I simply &quo... "/a" is not "/a" ? Hi everybody, while testing a module today I stumbled on something that I can work around but I don't quite understand. >>> a = "a" >>> b = "a" >>> a == b True >>> a is b True >>> c = "/a" >>> d = "/a" >>> c == d True # all good so far >>> c is d False # eeeeek! Why c and d point to two different objects with an identical string content rather than the same object? Manu Emanuele D'Arrigo wrote: >>>> c = "/a" >>>&... "or" and "and" Hi, I'm just getting to discover ruby, but I find it very nice programming language. I just still don't understand how the "or" and "and" in ruby... I was playing with ruby and for example made a def to print Stem and Leaf plot (for those who didn't have a statistics course or slept on it, e.g. http://cnx.org/content/m10157/latest/) Here is the Beta version of it: class Array def n ; self.size ; end def stem_and_leaf(st = 1) # if st != (2 or 5 or 10) then ; st = 1 ; end k = Hash.new(0) self.each {|x| k[x.to_f] += 1 } k = k.sort{|a, b| a[0].to_f <=&g... about "++" and "--" why this program snippet display "8,7,7,8,-7,-8" the program is: main() { int i=8; printf("%d\n%d\n%d\n%d\n%d\n%d\n",++i,--i,i++,i--,-i++,-i--); } > why this program snippet display "8,7,7,8,-7,-8" Ask your compiler-vendor because this result is IMHO implementation-defined. Check this out: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.15 http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.16 Regards, Irina Marudina fxc123@gmail.com wrote: > why this program snippet display "8,7,7,8,-7,-8&q... why "::", not "." Why does the method of modules use a dot, and the constants a double colon? e.g. Math::PI and Math.cos -- Posted via http://www.ruby-forum.com/. On Oct 26, 2010, at 01:48 , Oleg Igor wrote: > Why does the method of modules use a dot, and the constants a double > colon? > e.g. > Math::PI and Math.cos For the same reason why inner-classes/modules use double colon, because = they're constants and that's how you look up via constant namespace. Math::PI and ActiveRecord::Base are the same type of lookup... it is = just that Base is a module and PI is a float.... "out" and "in out" Hi i found the following explaination: In Ada, "in" parameters are similar to C++ const parameters. They are effectively read-only within the scope of the called subprogram. Ada "in out" parameters have a reliable initial value (that passed in from the calling subprogram) and may be modified within the scope of the called procedure. Ada "out" parameters have no reliable initial value, but are expected to be assigned a value within the called procedure. What does "have no reliable initial value" mean when considering the "out" parameter? By c... "my" and "our" Hi, while testing a program, I erroneously declared the same variable twice within a block, the first time with "my", the second time with "our": { my$fz = 'VTX_Link'; .... ( around 200 lines of code, all in the same block) our $fz = 'VTX_Linkset'; ... } So the initial contents of the$fz declared with "my" is lost, because "our" creates a lexical alias for the global $fz, thus overwriting the previous "my" declaration. It was my error, no question. But I wonder why Perl doesn't mention this - even with "use s... How to do PHP "require()" or TCL "source" in bash script I'm sorry but I can't figure out how to explain this any better than this. In PHP we have a command "require()" that obtains a file and logically places it into another file. I cannot figure out how to do this in bash script as the requirement is necessary for a migration script to obtain the code from a .cfg file and then be able for the "parent" script to run the code it "imported" from the .cfg file, much like PHP's require() or TCL's "source". This is what I have so far and it fails: if [ -f ivc.cfg ]; then cat ivc.cfg fi Anyone... "In" "Out" and "Trash" I just bought a new computer and I re-installed Eudora Light on my new computer. But when I open Eudora, the "In", "Out" and "Trash" links are not on the left side of the screen the way they were on my old computer. How can I get these links back on the left side of the screen? Thank you. On 25 Mar 2007 09:49:22 -0700, "abx" <abfunex@yahoo.com> wrote: >I just bought a new computer and I re-installed Eudora Light on my new >computer. But when I open Eudora, the "In", "Out" and "Trash" links >are ... Does it need a ";" at the very after of "if" and "for" write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if statement? marsarden said: > write code like: > > int main(void) > { > int a=10; > if(a<20) > {} > } > > Compiler ok on dev-cpp . don't we have to add a ";" after if > statement? The syntax for 'if' is: if(expression) statement There is no semicolon after the ) but before the statement. The statement is either a normal statement (which can be empty), ending in a semicolon:- if(expr) ... Looking for binary "expect" and "TCL/Tk" (if required) for OpenServer6 Does anybody know where to find "expect" (and related requirements) for OpenServer6? I can download the source files from nist.gov, but they do not compile. The MAN pages are already loaded on the system, so I suspect the programs would be on the distribution media somewhere. Any help would be appreciated. Thanks, Rick On 9 Feb, 17:57, Rick_Hoyle <motosl...@hotmail.com> wrote: > Does anybody know where to find "expect" (and related requirements) > for OpenServer6? I can download the source files from nist.gov, but > they do not compile. The MAN pages are al... PHP equivalent of TCL command "subst"? I need to find a PHP equivalent to a very familiar TCL command "subst" (see http://www.hume.com/html84/mann/subst.html ). This command will take a string and evaluate anything TCL inside of it and return values. for example, if this were my line: [TCL] set word {World} set line {Hello #word#} regsub -all {#([^#]+)#}$line {$$1} line return [subst line] [/TCL] My return should be Hello World and not Hello #word# Nor Hello word Because of a requirement for my app I am having to do the same kind of substitution variation, however, I am having to do it entirely in PHP. I don... How to open a pty from Tcl (or "please translate C example to Tcl") Hello out there, still struggling with getting TCP/IP to work in my somewhat bizarre setup (TCP/IP over 10.000 Volt power-line modems) I got a hint to try to use a pseudo tty. I got the advice --- What you would do is write a small C program (or perl, or any of a number of other languages). This program would call the "openpty" function, which: - Locates the next available (unused) pseudo-TTY device in the system, - Opens both ends of it, into two different descriptors, - Returns the file-descriptor numbers for the two ends (the "slave" end which mimics a tty, and the master end that your program will be using as the intercept point), and the filename of the slave (e.g. "/dev/ptya0"). --- Q1: Any way I could accomplish this from Tcl? Well, knowing nothing about openpty and pseude ttys I hunted around and found the following code snippet: --- /* * Allocate pseudo tty, returns master side fd. * Stores slave name in the first arg(must be large enough). */ int pty_open(char *sl_name) { int mr_fd; char ptyname[] = "/dev/ptyXY"; char ch[] = "pqrstuvwxyz"; char digit[] = "0123456789abcdefghijklmnopqrstuv"; int l, m; /* This algorithm should work for almost all standard Unices */ for(l=0; ch[l]; l++ ) { for(m=0; digit[m]; m++ ) { ptyname[8] = ch[l]; ptyname[9] = digit[m]; /* Open the master */ if( (mr_fd=open(ptyname, O_RDWR)) < 0 ) continue... Using "source" vs "package require" for Tcl application files I would like to divide my Tcl application into separate files. Should I generally use "source" to combine the files, or should I use the package mechanism (package provide, package require, etc.)? What is the generally accepted practice? Thanks, Gregg On 30 dec, 01:04, GB <g...@invalid.invalid> wrote: > I would like to divide my Tcl application into separate files. Should I > generally use "source" to combine the files, or should I use the package > mechanism (package provide, package require, etc.)? > > What is the generally accepted practice? > > Thanks, > > Gregg IMHO use [source]. My reasoning: - The package mechanism is meant for getting access to general-purpose libraries, installed directly under the Tcl installation. - You talk of source files for your own application. So I would expect these files to reside in a directory containing that application. Then [source] is easier to use - and you guarantee that you get the source files from your application (otherwise a random package with the same name from the installation could interfer, if you are not careful with the library path) - Using [source] also makes it clear that these files are meant for your application only, not for more general purposes. Regards, Arjen Arjen Markus wrote: > On 30 dec, 01:04, GB <g...@invalid.invalid> wrote: >> I would like to divide my Tcl application into separate files. Should I >> gen... Is there something like tcl "send" command in Python Is there somethin like tcl "send" command in Python. I would like to be able to exucate calls in a python program on one machine from another machine. Peter Gordon wrote: > Is there somethin like tcl "send" command in Python. I would like to > be able to exucate calls in a python program on one machine from > another machine. After you added some infrastructure such as Pyro (http://pyro.sourceforge.net), you can essentially invoke methods on objects on arbitrary machines. --Irmen Irmen de Jong wrote: > Peter Gordon wrote: >> Is there somethin like tcl ... Generating Tcl extension with Swig--"invalid command" -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I'm having problems turning functions that are defined in a C header file into Tcl commands via Swig. I have set up the interface file correctly (as far as I can tell), I generate a C wrapper with appropriate flags from Swig, and then I compile into a shared library. When I load the library into tclsh, it loads correctly. But then I am unable to execute any commands from the library, and I suspect it's because I'm not defining the functions correctly in my interface file. Here's one of the functions I'm trying to convert to a Tcl command. The specific function is "AHRegisterHelpBook," and is defined as such in the header file: extern OSStatus AHRegisterHelpBook(const FSRef * appBundleRef) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER; What do I need to add to my interface file to convert this function into a Tcl command? Right now my interface file is set up in this fashion: %module tclAppleHelp %{ ~ //insert entire contents of "AppleHelp.h" here, about 230 loc %} I haven't defined any functions outside of what is defined in the header file, because it's already defined in the header file. I'm converting this to a C wrapper with this tag: swig -tcl -namespace tclAppleHelp.i What I want to do is run a Tcl command this way: ::tclAppleHelp::AHRegisterHelpBook Attempting this command after successfully loading the library into tclsh yields an error message ("invalid... question about excecute a Tcl command by "echo...... | tclsh" Hi there, I am trying to excecute some TCL command in MS-DOS prompt, as I want to pass the command to another program " Labview", I use the following method: echo set w 1;set w |tclsh I found I can not get the value "w" , the only way I can show the value of "w" is to put a "puts" command in front of a command. For example: echo set w 1;puts [set w] |tclsh 1 my question is: are there anyway to avoid using "puts" to get the value, because if I have several TCL commands, in order to get the value, I have to put "puts" in front of every TCL command, that's not convenient. thanks, Mike On Aug 21, 7:56 am, mike.hfzh...@gmail.com wrote: > Hi there, > I am trying to excecute some TCL command in MS-DOS prompt, as I want > to pass the command to another program " Labview", I use the following > method: > > echo set w 1;set w |tclsh > > I found I can not get the value "w" , the only way I can show the > value of "w" is to put a "puts" command in front of a command. For > example: > > echo set w 1;puts [set w] |tclsh > 1 > > my question is: are there anyway to avoid using "puts" to get the > value, because if I have several TCL commands, in order to get the > value, You are getting two separate concepts mixed up here. Your first attempt is already correct and the last command, [set w] already "gets" the va... Is "Strategic Command" = "Strategic Command European Theatre"? I've seen some discussion here of a game usually referenced as "Strategic Command" and decided to give it a try. Searching for it, I found a game at battlefront.com called Strategic Command European Theatre - is that the same game? I guess I had the impression that the game covered the whole globe, not just Europe/Med area. If this is the same game, I have another question: from the screenshots, it appears that you only have one unit in each hex, is that correct? No stacking at all? I will probably have more questions before I decide to plunk down my$$\$, but I first...

Eliminate the need for "{}" or "\ " after commands?
Hello. Usually, a TeX command in text mode will eat a trailing space, so if you want a space after the command in the final document, you have to put a "{}" or "\ " after the command. For example, "\TeX book" will produce "TeXbook", whereas "\TeX{} book" or "\TeX\ book" will produce "TeX book". It seems there is a way around this. By chance I was looking at the source code for the documentation for the package "etoolbox". I notice that it has some command names followed simply by spaces - and the spaces show up in the TeX'ed output. This appears to be a result of the "ltxdockit" document class. Here is a minimal working example: \documentclass{ltxdockit} \begin{document} \tex book, \tex{}book, \tex-book \end{document} This produces the output: TeX book, TeXbook, TeX-book I have taken a look at the source code for the "ltxdockit" document class, but it is much too wicked code for me to figure out. Can anyone tell me what is going on? If there is a way to eliminate the need for "{}" or "\ " after commands, then I would love to know it. Thanks in advance. Claus Appel On May 9, 12:56=A0am, "Spectrum (Claus Appel)" <spectru...@gmail.com> wrote: > Hello. > > Usually, a TeX command in text mode will eat a trailing space, so if > you want a space after the command in the final document, you have to > put a "{}"...

"Vectors" in tcl?
Hi all, What is my "best" alternative in handling vectors in Tcl? ("best" as in using a package available in ActiveTcl. I know about VecTcl, but...) I want to use a vector (potentially large, as in half a million boolean values). If this vector is created with all zeros, and I want to turn some of them (I have their indices as a tcl list) to 1. Right now I am using a tcl list, but I need to loop over this list, and set each one to 1. And I was wondering if there is a faster way (as in doing it with a single tcl command). I was looking at the the math:...

"open with" tcl