| |||||||||||
returning from interact Posted by rookie (rookie), 4 December 2003 dear advanced programmer(s), as my login name implied, i am a rookie using expect. i am working on a few simple programs to get the feel of expect, but i am stuck already, here is my proble:i wrote a simple tcl program -- prog.tcl, it basically reads input from a very simple survey --survey.txt and is populated like so: what is your first name: what is your last name: and so on. now, prog.tcl works by reading one line from survey.txt and prompt the user for input, then reads the next line and promot the next input and so on. but now i want to use expect to act as a front line of prog.tcl since it doesn't restrict input format...like spaces for example....so my expect program sort of looks like: spawn tclsh /usr/home/bin/prog.tcl expect "what is your first name:" interact " " {puts "no spaces allowed"} } expect "what is your last name:" {send "LASTNAME\r"} how do i return to the script to the spawned program and that LASTNAME is automatically entered? the I've tested the expect program using 'send' command and it works great....for automated processes, but whenever i used interact it always screwing me up, I tired break, continue, and return after the interact command...but it all gives me back junk saying "invalid spawned id (4) "or something like that, and also, following the interact, the next expect just wait for user to type inputs in instead of sending "LASTNAME" to the prompt, which it should...i think. to all you masters....PLEASE HELP!! Posted by admin (Graham Ellis), 4 December 2003 Err ... I'm taking a step back from the interact problem, and going to ask you why you're using expect in the application - I'm not sure that I fully understand. from your description, I wonder if a script using puts and gets might do the job just as well, with you checking the string you get back from gets with a string handling function of regular expression.The way you're writing the code, it looks as if you're attemting to get back from interact as soon as the user presses a space key on the keyboard. Is that really what you want to do? It can be done BUT it's much harder than using puts/gets and it might frighten your users when the program continues before they even press enter. If you can confirm that you really do want to get the raw input, I'll have a play about in the next 48 hours and see if I can come up with a short worked example. Posted by rookie (rookie), 4 December 2003 thank you for your timely reply! the reason i am using expect is that i am taking a project class in CS, and the objective is to learn and come up with tutorial cases where programs written in tcl can be tested without modifing original code....which is why i am tempting to not write prog.tcl to handle any errors but leave that to expect in order to demonstrate the abilities of expect.....from that program, i am wishing to accomplish with expect : 1. remove white spaces from user input when prompted 2. make sure only number characters are allowed in related prompts such as phone# and zip code Posted by admin (Graham Ellis), 5 December 2003 I would tend to have my expect program use "conventional" spawn, send and expects to control the program being tested, and to use puts, gets and regular Tcl logic in the controlling program. I don't think you need interact; the prime use that I've come across for interact is to help you establish a connection to a difficult-to reach system, perhaps with a series of telnet / ssh type links and passwords, then leve the user logged on to that system - a different application to what you are describing.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.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |