rhymejerky has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have looked at the Expect.pm questions on this site, but I still have problem using this module. My code is
$expect = new Expect(); $expect->log_file("./res", "w"); $expect->spawn("/bin/bash"); $expect->expect(10,-re,'bash'); $expect->send($cmd); $expect->expect(10,'-re','Enter'); $expect->send($pwd);
The $cmd is just a command that performs some maintenance and the $pwd is the password to start it. My problem is this code always hangs at the password. When I run the script with -d, it seems like the $cmd is not sent when I do $expect->send($cmd). It sends the cmd out after the $expect->expect(10,'-re','Enter'). I can see that in the debugger as well as the log file for this expect. Any idea what is happening? Thanks

Replies are listed 'Best First'.
Re: Expect.pm problem
by tachyon (Chancellor) on Nov 25, 2004 at 03:59 UTC

    I expect that the problem is the lack of quotes around '-re' in your 4th line. If that fails you should set debugging on in Expect:

    $Expect::Debug = 3; # or $obj->debug(3);

    cheers

    tachyon

      I don't have quotes around my -re and it works. It looks like your first instance of -re works, too. It does not have quotes.
      I suspect that if you remove the quotes on the last one it would work. In any case, I don't think you would be hanging on your last "send" command. I think it is the quoted -re line above it. Good luck.
        I have taken out all the quote in the -re, but the problem persisted. I know expect.pm works if I execute commands,(ie., ls, cat etc) when the prompt shows up at the end of the command execution. When I run other command (Oracle calendar command to be exact), it does not get back to the prompt. Instead, it shows a line that asks me for password. I have a feeling that expect is not looking at the right place. Any other suggestion is greatly appreciated. Thanks