| |||||||||||
tcl read & puts & fconfigure problem Posted by anna (anna), 26 October 2003 proc x {command} {set handle [open "|$command" RDWR]; fconfigure $handle -blocking 0 -buffering none puts stdout $handle } proc w {data} { puts $handle $data } in tcl shell i execute: x {simv} ------file96 w {c 0} ----- error writing "file96": broken pipe how to solve this problem and i am so confused about the command "fconfigure", could anyone help. many thanks. Posted by admin (Graham Ellis), 26 October 2003 Hi, Anna, and welcome to the board.Have you posted the complete example? Your handle variable isn't declared as global or upvar in either proc, so I would have expected you to get an error message can't read "handle": no such variable with your code and test .... I tried running your code (replacing simv with a command I have on my system) and got the error I expected .... Posted by anna (anna), 26 October 2003 sorry the example is not so complete, i paste the complete source code here:set handle 0 proc x {command} { global handle set handle [open "|$command" RDWR]; fconfigure $handle -blocking 0 -buffering none puts stdout $handle } proc w {data} { global handle #puts stdout "i am in w" #puts stdout $handle puts $handle $data } btw: where can i download the tcl library ( i want to use the crc function) Posted by admin (Graham Ellis), 26 October 2003 I think your simv command doesn't expect any inputs, so as soon as you fire it off with the x proc, it runs to completion. In order to try out this theory, I saved you code (into a file called anna) and ran it twice - once using the more command which requires user input, and this ran perfectly, and once using the ls command which does not require user input ... which failed in the same way that your program did. Here's the output:Code:
I'm not familiar with simv - I suspect that it's a local program you have on your computer, but my guess is that it's run to completion before you run the w proc - thus leaving the handle variable pointing at a broken pipe. Posted by anna (anna), 27 October 2003 many thanks, it's very helpful...... This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |