my $ref = $exp->send("$cmd\n"); sleep(1); $ref = $exp->expect(TIMEOUT, [ $shell_prompts ] ); if (!$ref){ $log->warn("Timeout received!"); return -1; } $output = $exp->exp_before(); $output =~ s/^.*\r\n(.*)/$1/;
for multiple lines you must also split all lines
my @values = split(/\r\n/, $output); foreach my $val (@values) { print "$val\n"; }
For debugging all characters in output string please use next code (decode all characters to ASCII):
sub ENCRYPT_DECRYPT() { my $Str_Message=$_[0]; my $Len_Str_Message=length($Str_Message); my $Str_Encrypted_Message=""; for (my $Position = 0;$Position<$Len_Str_Message;$Position++){ my $Key_To_Use = (($Len_Str_Message+$Position)+1); $Key_To_Use =(255+$Key_To_Use) % 255; my $Byte_To_Be_Encrypted = substr($Str_Message, $Position, 1) +; my $Ascii_Num_Byte_To_Encrypt = ord($Byte_To_Be_Encrypted); print "$Ascii_Num_Byte_To_Encrypt\n"; my $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use; my $Encrypted_Byte = chr($Xored_Byte); $Str_Encrypted_Message .= $Encrypted_Byte; } return $Str_Encrypted_Message; } my $var=&ENCRYPT_DECRYPT($exp->exp_before());

In reply to Re: Perl "expect" script, capturing output not working by olibertu
in thread Perl "expect" script, capturing output not working by FirtyFree

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.