[ List Archives Home ] [ Thread index for 2008 ] [ Date index for 2008 ] [ Author index for 2008 ]


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Phil,
In order to determine if a review file is empty or not, you can use an
expect statement like the one below.

send "042"
expect {
"LIST RECORDS" {send "ny"}
"Copy an existing file" {send "2"}
}
expect "BOOLEAN SEARCH of FILE"
send "i"
expect "Find ITEM records that satisfy"
**etc.**

This fragment starts from selecting the review file number, and then
includes one expect statement with several choices for matching text.
The program should see either "LIST RECORDS" which happens if the file has
records in it, or "Copy an existing file" which happens if the file is
empty. The keystrokes of what to do in each case follow in braces. When
you group patterns into one expect statement, expect tries each pattern
and stops when it finds a match. If it doesn't find a match, it just
continues with the next statement. If you want to exit the script in case
there are no matches (which won't happen in this case since a review file
is either empty or full), then you can add a special timeout pattern which
tells the script what to do if it hits the timeout value rather than
matching anything.

expect {
"LIST RECORDS" {send "ny"}
"Copy an existing file" {send "2"}
timeout {exit}
}

You may be able to use this type of construct for the other problem of
skipping the listing statements if the review file comes up empty. You
can find more about this on p.75 and p.94 of "Exploring Expect."

--
Martha Driscoll, Systems Manager
North of Boston Library Exchange (NOBLE)
driscoll@xxxxxxxxxx
Ph: 978-777-8844 Fax: 978-750-8472

On Mon, 26 Apr 2004, Phil Shirley wrote:

> I've been using Expect scripts and Perl scripts to generate title lists
> for my web site (and for other purposes) thanks to the kind folks at NOBLE
> who put up the howto on their Swapshop. This works great except for (1)
> when I can't predict whether the review file will be empty or not when I
> start, and (2) when I can't be sure that the query will produce a non-zero
> number of records. Could somebody send me an example of how you handle
> things like this?
>
> More details: I have a report to find problems, which I would like to run
> every night with no intervention necessary (using cron); often it will
> find no records. If it gets zero results, I'd like to skip over all the
> instructions for printing and have it continue on to the next part of the
> report or to the end. Also, because it might leave the review file empty
> or not empty, the next time it runs I'd like it to be able to deal with
> either of these cases (currently the script expects that the file will not
> be empty).
>
> I have found examples of having the script send different things based on
> what it receives from the server, but nothing about branching to a
> different part of the script based on what it receives. Thanks for any
> help you can give me.
>
> Phil
>
> Phil Shirley
> Technology Services Coordinator
> Cuyahoga Falls Library
> Cuyahoga Falls, Ohio
> pshirley@xxxxxxxxxx
>
>
> --
> This message was distributed through the Innovative Users Group INNOPAC list
> Public replies: INNOPAC@xxxxxxxxxx
> Update your subscription options: http://innopacusers.org/mailman/listinfo/innopac
>