Loading ...
Sorry, an error occurred while loading the content.

Expect - Timing issue

Expand Messages
  • Sreeram B S
    Hi friends, I am using Expect to automate an interactive task. I could accomplish the task, but there is one serious problem with respect to timing. It so
    Message 1 of 1 , Dec 29, 2005
    • 0 Attachment
      Hi friends,
      I am using Expect to automate an interactive task. I could accomplish the task, but there is one serious problem with respect to timing.

      It so happens that, the program sends the next command to the expect-handler before the first command completes execution. So, there are chances that few commands will not get executed or sometimes the results are undefined.

      For eg:

      #!/usr/bin/perl

      use Expect;

      $handle = Expect->spawn("telnet machine1");
      $handle->expect(10,"gin: ");
      $handle->send("guest\r");
      $handle->expect(10,"word: ");
      $handle->send("guest\r");
      $handle->expect(10,"\$ "); "$ " is the prompt.

      ## Sending commands.
      $cmd = "date";
      $handle->send("$cmd\r");
      $handle->expect(10, "\$ ");

      $cmd = "cat /etc/hosts";
      $handle->send("$cmd\r");
      $handle->expect(20,"\$ ");

      $cmd = "ls"; ## This command may get executed before "cat" command is complete
      $handle->send("$cmd\r");
      $handle->expect(20,"\$ ");

      ## End of sending commands.
      $handle->soft_close();

      ### End of script ###

      Here, it so happens that the third command (ie "ls"), will be sent to the machine and get executed, before second command (ie "cat /etc/hosts") has finished execution. This may lead to undefined results.
      So, how do I ensure that the next command is sent only after the completion of the previous command?

      There is one way which I found in the web, ie using "send_slow". Yes, this can be used and it works fine. But the problem with using "send_slow" is that the program becomes too slow.

      So, how can I achieve effecient execution as well as good timing/speed ?

      Kindly suggest.

      Regards,
      Sreeram




      ---------------------------------
      Yahoo! Photos
      Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.