ok. i'm using Expect.pm to (surprise!) automate a console program. what i occasionally need to do is parse what has been done so far, make a decision about what has happend, and then do 'a' or 'b' depending on what was dumped to the screen. normal expect matching doesn't work for what i need, so i've been doing something like this:
#jumping into the relevent bits...
$command->log_file(undef);
if ($command->expect(2,"/>")){
$command->log_file("$TEMPFILE") or die;
print $command "<i>COMMAND</i>\r";
}
if ($command->expect(5,"/>")){
$command->log_file(undef);
}
open (LOG, "$TEMPFILE") or die;
@command_results=<LOG>;
close LOG;
i'm paraphrasing, but that's the gist of it. this way i can see the results of
COMMAND as @command_results. i then chop that up and have some other things happen that then prompt one of several other commands. normal expect matches don't work for me, mostly because much of this needs to be returned to the user at the end of the script. i also don't want to have to read/write a file for each time this is done for a variety of reasons, not least of which is the permissions on the folder this will be run from (nothing i can control).
so, i have 2 questions:
1. can i have a filehandle to point the expect log at that isn't actually a file?
2. is there a better way to grab the output of a command with Expect.pm than using the log file?
edited: Tue Apr 8 22:30:17 2003
by jeffa - code tags
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.