expect on a socket
Posted by sirius_black (sirius_black), 6 November 2003Hello 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]imel.org
Posted by admin (Graham Ellis), 7 November 2003I 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 ?)
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho