Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Returning a string from EXPECT SCRIPT

    Hello All,

    I have an expect script, which does SSH into an remote machine and executes a certain command. I capture the result of command using Expect and is available within script under $expect_out(buffer). My issue is that i am calling my expect script from another PERL script and i need to access the string stored in $expect_out(buffer) in my calling PERL SCRIPTING FOR SOME PROCESSING, please suggest if it possible.
    Thanks in advance for your suggestions
    Nitesh Bansal

  2. #2
    first thing that leaps to mind: is there some reason why you are not using the Perl Expect module?

    i'll assume that there is, and you must use an external expect script. in your case, the first thing i'd do is modify the expect script to output the buffer in an obvious line, something like:

    set foo $expect_out(buffer)
    send_user "\n\n<output>$foo</output>\n\n"
    then in your perl script, when you call the expect script, capture the output of the script and parse it, looking for the above <output> string, e.g.:

    local $/ = undef;
    open(PH,'/tmp/script.exp |') or die "can't run script.exp: $!\n";
    my $lines = readline(*PH);
    # replace carriage return & newline from expect w/just newline
    $lines =~ s/\r\n/\n/g;
    my @lines = split(/\n/,$lines);
    my $done;
    my @match;
        $done = 1;
        push(@match,$_) if($#match>=0);
      print "MATCH: ",$_,"\n";
    Note: that could have been done more easily, i just got sideways and kept going...

  3. #3
    Thanks for reply mate.
    It is working fine now, your suggestion has been helpful and yeah its working

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts