Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 913559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:34:55+00:00 2026-05-15T17:34:55+00:00

I am using Expect in perl to connect to remote machine and execute certain

  • 0

I am using Expect in perl to connect to remote machine and execute certain functions. sample code is like

$outfile="ls -lrt";
$outfile1="output";

$exp->expect(30,-re,".*bash-.*" => sub{$exp->send("$outfile2 >$outfile \r")});
$exp->expect(60,-re,".*bash-.*" => sub{$exp->send("$shayam > $Ram \r")});

Even if the first expression fails it will wait for 60 sec and will execute the second statement. I just want to make a check that if only the first statement passes it should proceed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:34:56+00:00Added an answer on May 15, 2026 at 5:34 pm

    I am guessing you are using the Expect.pm module documented here. As stated there:

    If called in an array context expect()
    will return
    ($matched_pattern_position, $error,
    $successfully_matching_string,
    $before_match, and $after_match).

    So you likely want to call it in array context so you can get an error, both if the regex fails and if the send fails.

    my ($matched_pattern_position, $error,
      $successfully_matching_string,
      $before_match, $after_match) =
      $exp->expect(30
      , -re,".*bash-.*" =>
        sub{$exp->send("$outfile2 >$outfile \r")}
    );
    
    $exp->expect(60
      ,-re,".*bash-.*" =>
        sub{$exp->send("$shayam > $Ram \r")}
    ) if !defined $error;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using NUnit mocks and would like to specify that I expect a call
When using a statement like #if TRUE , what should I expect to happen?
I have an expect file that looks like this. I invoke the script using
I'm using Perl's format and write functions to output some text. The requirements are
How can we copy the files recursively to the remote server using expect script
While connecting to the remote host using the Net::SSH::Expect module , 2 out of
print $tree->findvalue('//a[1]'); I am using HTML::TreeBuilder::XPath in perl. Now i expect the above statment
I connect to a VPN from console using something like: sudo openvpn my.conf [sudo]
I am new to using expect, and I've searched for an answer to the
I'm using expect to respond to a network service. However, I've noticed in Wireshark,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.