Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/tcl-read-amp-puts-amp-fconfigure-problem.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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:
[localhost:~/oct03] graham% wish
% source anna
% x more
file11
% w hello
% exit
[localhost:~/oct03] graham% wish
% source anna
% x ls
file11
% w hello
error writing "file11": broken pipe
%


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.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho