03.11.2014 Views

Tcl/Tk quick start - Free

Tcl/Tk quick start - Free

Tcl/Tk quick start - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Presented by developerWorks, your source for great tutorials<br />

ibm.com/developerWorks<br />

default.<br />

What you can do with Expect<br />

When your script invokes an interactive program, by default Expect intercepts all input and<br />

output (STDIN, STDOUT, and STDERR). This allows Expect to search for patterns that<br />

match the output of the program, and send input to the spawned process to simulate user<br />

interaction. Additionally, Expect can pass control of a process to a user if so instructed, or<br />

take control back upon request.<br />

Not only do these traits make Expect remarkably useful for common administrative tasks, but<br />

it turns out that Expect is quite good for building test scripts to perform I/O validation during<br />

program development.<br />

Finally, there's the stunningly useful program, autoexpect. Itself an Expect script,<br />

autoexpect monitors a command line interactive program, generating an Expect script that<br />

replicates that interaction exactly. Now, while that usually isn't just what's needed, it is easy<br />

to take the results of several autoexpect sessions, generalize the expect patterns, then cut<br />

and paste them into the desired configuration. It's been written in more than one place that<br />

the best learning tool for Expect is to run autoexpect and play with the results.<br />

<strong>Tcl</strong>/<strong>Tk</strong> <strong>quick</strong> <strong>start</strong> Page 24 of 29

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!