Problems using Expect to parse a file



Sorry if this is a well known problem; I have tried to find any pre-existing solution searching the web and buying "Exploring Expect", but not got anywhere.

I'm trying to write a script to automate a program called DeltaE, a powerful thermoacoustic design tool (with, unfortunately, a ghastly menu-only interface), and to extract performance data from the simulations it runs by parsing through its output files. For reference, I'm using Linux AMD64, with the DeltaE.exe program running under Wine.
I've just about got the hang of driving the menus in Expect, but I'm having real trouble extracting the performance data.

My first attempt was to load the (plain text) output file as a process, as Expect is supposed to be capable of doing, then running the appropriate expect commands on its spawn_id. The trouble is, all this does is load the whole file into the expect buffers in one go, which would be OK on its own, but then of course it detects the eof and immediately closes the process again, and so all the subsequent expect commands acting on the buffer seem to fail because they don't have a valid process id to interact with. Is there any possibility of working around this problem? The relevant code for that attempt looks like this (apologies if my particular indenting style is annoying):


set fidOutput [open "data/$n.out" r]
spawn -open $fidOutput
for {set m 1} {m <= 3} {incr m} \
{
expect "HX" etc...
}


Where $n is the numeric filename and "HX" is the marker preceding the first of three pieces of data to extract.

Since I couldn't figure out a way to fix that directly, I decided to follow the Expect philosophy of running the program the way a human would do and spawn a program to read the file. cat and more couldn't be used, because they dump all the data and immediately terminate, causing the same "loss of process" problem as before. Less, on the other hand, remains open upon reaching the end of a file until it receives the "q" command, so I tried writing a script to step through the file using that, as follows:


spawn less "-c data/$n.out"
set pidLess $spawn_id
send "\r"
for {set m 1} {$m <= 3} {incr m} \
{
set bHX 0
while { !($bHX) } \
{
expect \
{
"HX" {set bHX 1 ; etc}
"\n\:" {send "\r"
}
}
}


Which should, I think, cycle through all the pages of the file displayed by Less until finding an instance of "HX", then extract the following data. The "-c" parameter makes Less print each page top to bottom, so that the prompt, which I am using to signify the end of the page, is not seen by expect before the page itself is actually displayed. The trouble now is, although manually executing the command "less -c data/1.out" at a tty functions just as you would expect it to, when Expect sends the exact same command as part of the spawn process, and running the script with exp_internal true, apparently none of the data sent to the display by less when started normally is being seen by Expect - all it seems to get is "No tags file\r\n", followed by eof and closure of Less - I'm afraid I haven't a clue what the "No tags file" statement means.

Can anyone help me with any of this mess? The whole script is pretty large and sprawling so I've only posted snippets, but I'll put up the whole thing if anyone needs it.

Thanks.

Tom
.



Relevant Pages

  • Re: about shell pgms
    ... IN MY PROJECT I HAVE TO: Create a UNIX shell script named user_menu ... Therefore valid entriesof this command by the user are: ... If either is incorrect, display the generic ... display the generic usage message. ...
    (comp.unix.programmer)
  • Re: Why is this script so slow?
    ... | mysql database that has about 250 records in it. ... | When I use another script to extract the same data and display the ... | I can only conclude it is the script. ...
    (alt.php)
  • Re: Display korn shell script interactively
    ... I have a ksh shell script which calls another ... cursor position at the place and display one line below it as ... Please wait " with a dot moving from one end to other ... ment is to call the command and while it is processing i need to ...
    (comp.unix.shell)
  • Re: Display korn shell script interactively
    ... I have a ksh shell script which calls another ... cursor position at the place and display one line below it as ... Please wait " with a dot moving from one end to other ... ment is to call the command and while it is processing i need to ...
    (comp.unix.shell)
  • Re: DTS Scheduled Job
    ... execute the script as a vbscript with the credentials of the Agent account ... or run the command from the command line using you credentials ... make your script write the command output to a file... ... > the package is to extract a zipped file into a folder, ...
    (microsoft.public.sqlserver.dts)