Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
expect on a socket

Posted by sirius_black (sirius_black), 6 November 2003
Hello everybody !!
I'm french so I'm not sure you will understand all the things I want to say  
I'm looking for a method tu use expect with socket
something like (If it would exists) :

set s [ socket localhost 9876 ]
expect -channel $s "ping!"
puts $s "pong!"

So I don't want to use expect with a classic "spawn telnet" because I want to create a program which can run on every platform running Tcl/Expect and only Tcl/Expect (no need of telnet).

So my question is :
how can I redirect the stream of the socket to Expect ?

If you want to contact me : sirius_black[at]

Posted by admin (Graham Ellis), 7 November 2003
I think I understand the question - and if I don't, it's just because I'm not yet fully awake this morning  

Spawn usually works with processes, as you say, but it can also work with files and devices using the -open option.   To quote Don Libes, the author of Expect, "The spawn command does not provide any facility for redirection or pipelines becuase the need for it is almost non-existent".   I wonder if he took the same view about sockets; he also says "to communicate with sockets, Expect can spawn telnet".

Have you considered using raw Tcl (rather than Expect) for your application?   The main niche that Expect is designed for is  automating those awkward programs which only provide user / command line interfaces, wheras programs that run to sockets are typically designed to talk to other programs and you probably don't need all the special facilities of Expect .... just a thought - the facilities for socket handling in Tcl are quite good, if underutilised!

Posted by sirius_black (sirius_black), 7 November 2003

Thank you for your answer.
Yes you have understood what I wanted to say.
I'll try 'raw Tcl' with socket (read and if) but it would be better to use Expect with socket (maybe in the next version of Expect ?)
Thanks !

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

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