From: pjyamamo@watdragon.uwaterloo.ca (Peter Yamamoto)
Subject: Apology + ANSWER + more questions [expect] (was Re: How to...)
Reply-To: pjyamamoto@watdragon.uwaterloo.ca
Organization: University of Waterloo
Date: Sat, 3 Oct 1992 14:29:10 GMT

In article <92Oct1.171707edt.168199-1@watdragon.uwaterloo.ca> *I*
pjyamamo@watdragon.uwaterloo.ca (Peter Yamamoto) writes:
>Sorry if this is an FAQ but I have read through man pages
>and documents and ....

Ok, pre-apologies and polite requests weren't enough to stem the
request to abide by USENET rules so...
How does one get around this? I am sorry I asked...
Now I think this is also "against" USENET rules so apologies again:

(partially) Answering my own questions!...

I hadn't "expect"ed to be able to play with this much but
I put some experimentation in and a helpful hint from one reader,
the "log_file" which wasn't what I asked for below but helped
me see where things were going wrong, got me going again...

>I wrote a script to connect to our library's on-line
>catalogue and to look up issn #'s given a file of call no's.
>the output basicly looks like
>FIELDHEADER: field value^M
>where I write ^ and M here but of course I mean CTL-M.
>so I match something like:
>-re "ISSN: (\[^^M\]+)" {set issn expect_out(1,string)}
>which as I say works ok but...
>Sometimes it doesn't catch the whole string.
>I can see that it started to match since it prints out some
>prefix but it doesn't always catch it [match completely to the ^M].
>
>Is this possibly because the output from the catalogue system
>is coming too fast (and if so wat can I do?)
>or is something else inherent in the expect statement:

[I tried increasing buffer size but the amount of text between
matches wasn't exceedingthe default buffer size anyways]

Well, as far as I can tell the fix for this was adding
a little more to the match:

-re "ISSN: (\[^^M\]+)^M" {set issn expect_out(1,string)}
                     **

This apparently makes it match completely to just before the ^M!
Now, in my opinion, with respect to the contents of the (), the
two expressions should match the same things.

This makes me think that something is not quite in sync within
expect: Ie something sees a "^M" and is telling the matcher to stop
before the matcher actually reaches that match?

>Oh yeah and if there is an easier way of collecting the output in a file
>than send_user and redirecting the script's output into a file,
>please tell me.

Somebody told me about log_file which helped me BUT it is still not
what I want.

The script is playing with the on-line catalogue. All I want is
the matched data (along with the input callno) printed out above.
I have 2 problems:

1. the "send_user blah\r" command sends out an extra CR so the output
is double spaced. How do I get single spaced output?

2. I would prefer not to send the data to stdout or stderr and
redirect output from the script but to put the data in a file and
leave open the possibility of stdout for user control/intervention.
Do I spawn a "cat > outfile"? Seems inefficient; is there a more direct
way?

>Standard request: PLEASE at least Cc: answers via email as I do not
>regularly read this group. If anybody is interested in the answer email
>me and I will forward any (hopefully some) replies.

Some people didn't like this request. The main reason I asked is because
in general a posting can take a couple weeks to reach here; especially
since recently we have been having some news feed problems on some
machines. Asking for a carbon copy of a response is, in my opinion, no
big deal; however, if it offends you, then just post, I will, according
to USENET rules, peruse this newsgroup for follow-ups.

Peter