
Journal morgan_greywolf's Journal: The Tcl/Expect Rant
First off, let me say that Expect is an awesome tool. It's great, especially, for writing GUI front-ends to CLI applications. Of course, if you want a nice-looking fully-modern GUI, you're not going going to be using Expectk. The Tk toolkit is ugly and ancient.
Now enters Python, PyGTKand Pexpect. Pexpect, for those who don't know, is a pure Python Expect-like module.
Pexpect is great -- right up until you need to run on Windows. After that, well, you seem to be pretty much out of luck with Pexpect, as it can't run on Windows, since it relies on Python's pty module, which is not available on Windows.
So, in looking around for other Expect implementations -- it seems none of those work on Windows, either -- with one exception: the Don Libes original Expect, which now runs on Windows.
Great! Only one problem: now I have to write my CLI handling code in Tcl.
Let me just say that Tcl sucks. It's horrible. Maybe you like functional programming, like Ruby or Lisp or Scheme. I hate it. I'm an OOP guy. I prefer OOP. Yes, I know about XOTcl, etc., but at the end of the day these extensions are like putting lipstick on a pig. (Ha! Thanks to the 2008 Presidential Election, I now LOVE this expression!
For example, in GUI-front-end writing, you often need to build your command line from a list of arguments. With Pexpect, you just do something like this:
from pexpect import *
command="mycommand"
switches="%s -a %s" % (switches, argument_for_a)
cmdline='%s %s' % (command,switches)
child=spawn(cmdline)
With Tcl Expect, you'd think you could do something similar:
set command "mycommand"
append switches [format "-a %s" $argument_for_a]
set cmdline $command
append cmdline [format " %s" % $switches]
exp_spawn $cmdline $switches
But, nooooo. Expect passes $switches as one big-long fsckin' argument
Ok, fine. Pass it a list! Change everything to lappend, etc., and that should work right?
Nooooo. Then Expect mangles it even worse and passes the list like this:
"{arg 1} {arg 2} {arg 3}" -- literally. Braces and all.
Grrr.. Okay, looking closer, exp_spawn expects to see each argument to the program passed as a separate argument. Okay, there must be some way to break a list into separate args.
There is. In Tcl 8.5. It's called 'expand'. Never mind that ActiveTCL 8.5 doesn't come with Expect, and the only way, it seems, to get it is to pay for it. Fsck you, ActiveState.
So, I was working with ActiveTcl 8.4.19. Which doesn't have 'expand'. Nowhere in the docs is it mentioned what to do. I found a forum post, fortunately, and figured out that the 'eval' command will break a list passed to any command into separate arguments by forcing another round of expansion before calling the exp_spawn. It took me hours to find this little nibble of Tcl wisdom.
WTF? Why is Tcl so
Bleck. Tcl sucks.
Alternative viewpoints are welcome.
The Tcl/Expect Rant More Login
The Tcl/Expect Rant
Slashdot Top Deals