|
2 days
70% Lecture/30% Labs
Intermediate Level
Expect’s unparalleled support for interacting with command-line and network applications have made it the industry standard for automated test applications. But its features also make it an excellent tool for managing interprocess communication and extending legacy applications. As one developer said, “Expect can make easy all sorts of tasks that are prohibitively difficult with anything else.”
In this course you will learn
Core Expect commands
How Expect interacts with the operating system
Automated applications to avoid common pitfalls
Logging and debugging utilities for solving hard-to-find interaction problems
Power of regular expressions for pattern matching and data extraction
Advanced features for automating multiple applications simultaneously as well as handling user interaction
This course is recommended for people with a basic Tcl programming background who need to create Expect programs, particularly automated test, command-line automation, or network automation applications.
Students should have taken the Introduction to Tcl/Tk course, or have equivalent Tcl knowledge. This course is normally taught in a UNIX/Linux environment, so students should also be comfortable with basic UNIX/Linux operation, including file editing, basic shell operations (cd, ls, etc.), and basic file operations (moving, deleting, file permissions, etc.).
This is an intensive, interactive course, which is approximately 70% lecture and 30% lab. Questions are highly encouraged. On the final day, students are given access to a zipped file containing all of the solutions to the labs and the examples used throughout the notebook.
Introduction to Expect
Why Do We Need Expect?
Who Uses Expect?
Expect Architecture
Invoking and Using Expect
Core Expect Commands
Sending Strings (send)
Waiting for Input (expect)
Timeouts and the expect Command
Expect Commands and Variable Scoping
Starting a Process (spawn)
Sending to a Process
Different End-of-Line Characters in Different Situations
How Expect Interacts with a Process and a User
Reading from a Process
Partial Automation with interact
Lab 1
Expecting Multiple Patterns
Pattern Order is Important!
Detecting if expect Timeouts
Using timeout to Handle Error Cases
Detecting Process Termination
Glob Patterns in Expect
What Happens When expect Matches?
Character Buffering in Expect
Lab 2
Debugging Patterns
Enabling Diagnostic Output with exp_internal
Exercise 1
Strategies for Using exp_internal
Logging Process Output to a File
(Intentionally) Slowing Down Interaction
Basic vs. Advanced Regular Expressions
Basic Regular Expression Syntax Summary
The Tcl regexp Command
Using Anchors to Match Patterns at Beginning or End of Strings
Character Ranges
Exclusive Character Ranges
Escaping Special Characters
Subpatterns
Building Complex Regular Expressions
Capturing Subpatterns
The Tcl regsub Command
Exercise 2
Advanced Regular Expressions in Tcl 8.1 and Later
Potential Areas for Incompatibility
Backslash Escapes in Tcl
Noncapturing Subpatterns
Character Classes in Regular Expressions
Character Class Shorthand Escapes
Greedy vs. Non-Greedy Quantifiers
Using Bounds to Match a Specific Quantity
Useful Patterns
Which Regular Expressions Can You Use?
Using Regular Expressions with expect
Prompt Matching
Regular Expression Subpatterns and expect_out
The Most Useful Regular Expression for Expect!
Lab 3
Case-Insensitive Matching
Creating Persistent Expect Patterns
Closing Connections (close)
Waiting for a Process to Finish (wait)
Looping Using exp_continue
Managing a User and a Program
Sending Strings to the User
Filtering Process Output
Writing Error Messages
Reading from a User
Accessing Terminal After Redirection
Changing Terminal Modes
Cooked vs. Raw Mode
Prompting for Passwords
Patterns in interact
Patterns as “Macros”
Returning Control to the Script
Lab 4
Spawning Multiple Processes
Interaction through Implicit Spawn IDs
“Multicasting” to Several Processes
Interaction through Explicit Spawn IDs
“Listening” to Multiple Processes Simultaneously
Expecting the Same Pattern from Multiple Processes
Using Spawn Lists
Dynamically Maintaining a Spawn List
Using Indirect Spawn IDs
Treating the User as Another Process
Lab 5
|