Web Front - TCL/Expect Telnet Backend
Posted by jkurrle (jkurrle), 7 October 2004As many posters here, I am a newcomer to the TCL/Expect environment. However, despite my lack of previous training, I have found the language to be easily adaptable, except for one issue.
I have an Expect script that spawns a Telnet session and works flawlessly. It's great when I run it from a command line. I also have figured out how to pass parameters from a web form into a TCL CGI script. What I am running into is an issue with running a background automated telnet session on a web server.
This is procedurally what I want to do:
1) User selects some variables on a web page form and presses the form button to submit. (Got this)
2) Web form sends data to a TCL CGI script (this works)
3) The TCL/Expect script then spawns an automated background Telnet session, using the supplied parameters to manipulate a proprietary piece of hardware.
The problem I have is that once I try to spawn the Telnet session, the script errors out. Does someone have a working example of a web spawned background telnet session that I can take a look at and see what I'm doing wrong?
Any help would be appreciated. Thank you.
Posted by admin (Graham Ellis), 8 October 2004As a quick guess, I suspect you aren't doing a
and you're spawning your telnet before you send out your script headers?
Here's a working examle of expect used on a web page:
And you can run it via http://www.wellho.net/cgi-bin/demo/server.tce
Please post up a short piece of sample code to show the problem, and be a little more specific about how it fails (exact error message and/or description). That will help me give further advise.
Posted by neo (The Architect), 22 January 2005Slightly off topic but thought i might ask here anyway.
Can we automate FTP sessions using Tcl. I mean how do we send the password after connection to port 21 on any machine?
BTW is it necessary that sockets are used? is there any way i could just send out the 'ftp' commands from the Tk script and wait for a response?
Posted by admin (Graham Ellis), 22 January 2005Your side text says "the problem is choice" and how right you are.
Yes - you could simply use sockets (but as I understand FTP, it uses both a TCP and UDP connection ans isn't the easiest) OR you could use a prewritten set of procs that someone else has done the hard work with OR you could use expect. Personallu, I would use Expect provided that I had a suitable Unix / Linux based system (although I do see that ActiveState now offer a commerciaol license for a Windows expect that's probably good).
There's a simple example of using FTP through expect on our tcl course - here's a direct link
Posted by neo (The Architect), 22 January 2005I would like to use Tk for a GUI interface. In this case then if I use expect will not my app be dependent on both TCL, Tk and also expect (if i use expect)?
What if any one of those (tk OR expect)is not available?
Posted by neo (The Architect), 23 January 2005If TK is present can i assume that expect will also be present?
Posted by admin (Graham Ellis), 23 January 2005Both Tk and Expect require a "core" Tcl installation - so if you have expect or Tk you automatically have Tcl.
Tk is a GUI, so it needs a system with a good graphics basis underlying; X windows or a Microsoft window system is fine.
Expect makes a number of operating system calls and works in such a way that it needs a good underlying multiuser operating system on which to fucntion well. Historically, that's meant a Unix varient as the microsoft products originated from the desktop rather than from the server, and Unix systems the opposite way. However, these days most (if not all) of the weaknesses have been overcome in both directions.
Expect has been a very stable piece of software for many years - quite simply, it's fulfilled its function well, so why change it? The result, though, has been that support onto recent versions of Windows has been poor. The ActiveState version of Expect (for which you need a license ....) should be plugging the gap.
Posted by neo (The Architect), 23 January 2005How do i use expect scripts from my Tk app?
I tried the expect commands but they gave me errors.
Posted by admin (Graham Ellis), 23 January 2005You probably use a different executable with a name like expectk into which both are built
Posted by neo (The Architect), 24 January 2005is that expectk available for Linux/ Cygwin?
Posted by admin (Graham Ellis), 24 January 2005Linux - yes, for sure. Use it all the time.
Cygwin - dunno ... try googling for it
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho