Question

I have a expect session that looks similar to this:

spawn myapp
stratos> list-tenants
Available Tenants:
+-----------+-----------+-------------+--------+---------------------------+
| Domain    | Tenant ID | Email       | State  | Created Date              |
+-----------+-----------+-------------+--------+---------------------------+
| frank.com | 1         | foo@bar.com | Active | 2014-02-26T11:33:23+05:30 |
+-----------+-----------+-------------+--------+---------------------------+

stratos> 

The flow is roughly:

  1. The application outputs stratos>
  2. The user enters list-tenants
  3. The application outputs Available Tenants: with the table shown in the example above.

How can I match the output from step 3 in expect? I.e. what do I need to replace ????, below?

Note that the expect script is part of a test with the output generated by a mock service that the application calls, so I am expecting to match the whole output verbatim.

expect "stratos>"
send "list-tenants\r"
expect {
    ????           { exp_continue; }
    timeout        { puts stderr "Expect could not match 'Available Tenants:'"; exit 1; }
}

Many thanks.

Was it helpful?

Solution

Try this: (untested)

spawn myapp
set prompt_re {stratos> $}

expect -re $prompt_re
send -- "list-tenants\r"
expect {
    timeout {error "could not match available tenants"}
    -re "list-tenants(.+)$prompt_re"
}
set available_tenants [string trim $expect_out(1,string)]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top