merlyn is too quick to jump to a conclusion here. <G>

It seems that Expect combines the STDERR and STDOUT of the program together. By adding the parameter '2>errfile.tmp', kudra and I determined that the STDERR from the program will go to the 'errfile.tmp' file, and STDOUT will go where expected.

The output in 'errfile.tmp' can now be processed as desired. This works quite well for her application, although it would be cooler if the output could be tied straight into a scalar, rather than having to open the file for processing.

Note that 'errfile.tmp' is not an ideal name, as it's not process specific, nor garanteed. We're aware that there are some suggestions for creating unique filenames, but that wasn't the point of this node.

Perl Cookbook, section 16.7, talks about redirecting I/O.

Revised code:
my $object = Expect->spawn("program 2>errfile.tmp"); # 1 my $error = ($object->expect(30, 'password:'))[1]; # 2 die "$error\n" if ($error); # 3 print $object "incorrectpassword\r"; # 4 $object->soft_close(); # 5

--Chris

e-mail jcwren

In reply to (jcwren) RE: How to split output using Expect.pm by jcwren
in thread How to split output using Expect.pm by kudra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.