|Just another Perl shrine|
Bidirectional IPC with Expect and Passthroughby steve (Deacon)
|on May 07, 2011 at 03:50 UTC||Need Help??|
steve has asked for the
wisdom of the Perl Monks concerning the following question:
I would like to write a wrapper script for a *nix-based command line utility. Said utility while running is almost constantly printing information, and accepts input regularly regarding this information. What I would like to do is write a script that meets the following criteria:
The first two items here amount to straight passthrough as far as I am concerned. This is essentially the same user experience as running the program by itself outside of perl. The last item is essentially an expect script.
A good test case for this (although practically less useful) would be semi-automated control of some process like top.
Pipe Opens is documented as insufficient to meet this set of criteria. Bidirectional Communication with Another Process has some great information, but cautions that working with buffering and pseudo-ttys will ruin my day. Expect is suggested as the best solution for compatible environments.
With that wonderful documentation it seems that the solution lies with Expect as I had presupposed, but I am having some difficulty formulating a mental map of how this works logically. I have used Expect in the past for many things, but only to automate entire workflows, and not in an environment where user input may happen at any time, and the expect-controlled target never ceases to return results (does not wait for input).
Will always emulate the target until EOF, but does not afford any interactivity.
I fully Expect that the interconnect or interact method will be the solution to address these criteria simultaneously, but the documentation for such is rather sparse. Additionally I am finding the search for information on the Expect module to be very difficult due to the case-insensitive nature of most searching algorithms and the ubiquitous usage of the word expect in entirely unrelated topics.
While I am working on this I would like to ask if anyone else has dealt with this, and if they have any advice, other reference points, or sample code I could review.