Re: Expect problem

2001-05-23 Thread Mark Rogaski

An entity claiming to be [EMAIL PROTECTED] ([EMAIL PROTECTED]) 
wrote:
: 
: How can I get things to wait till the spawned program finishes, or at
: least let it finish properly.
: I've just had success by putting in an infinite wait
: unless ($command->expect(undef, "nonsense")) {
:};
: But that seems real stupid - and of course the script will never exit
: now.
: Is the only thing to do to to somehow get an expect method to somehow
: wait for the end of the spawned program?
: 

Try:  $command->interact();

It connects the process to STDIN and returns when the process dies.

Mark

-- 
[]   | "Girls in occupied countries always
[] Mark Rogaski  | get into trouble with soldiers," she
[] [EMAIL PROTECTED] | said, when I asked her what the Virgin
[]   | birth was.  -- Florence King, CoaFSL

 PGP signature


Expect problem

2001-05-23 Thread john . hearns

Hi all - time for me to delurk. (dashes in from the shadows).


I've bent my brain with Expect yesterday and today, and need someone to
(metaphorically)
hit me round the head and tell me what to do right.

The scenario:
I wish to run a program, imapxfer, which transfers imap email between
two imap servers.
Each server will prompt for a password.
Getting out the trusty Perl Cookbook, I'm trying to use Expect, which is
amost working.

Here is the code:

# use Expect to run the imapxfer progam and supply its inputs
 $command = Expect->spawn("/usr/local/bin/imapxfer $imapargs")
   or die "Couldn't start imapxfer";

# wait 20 seconds for the password: prompt
 unless ($command->expect(20, "password:")) {
  print "Timeout problem with London imapxfer \n";
  }
print $command "passwordr";

# wait 20 seconds for the password: prompt
unless ($command->expect(20, "password:")) {
 print "Timeout problem with newmail imapxfer \n";
  }
print $command "password\r";



Things are fine up until this point - the program starts off, and both
passwords are accepted.
But when the script exits the spawned program is killed :-(, which
happens pretty quickly.
I've tried the soft_close and hard_close methods, which aren't any use.

How can I get things to wait till the spawned program finishes, or at
least let it finish properly.
I've just had success by putting in an infinite wait
unless ($command->expect(undef, "nonsense")) {
   };
But that seems real stupid - and of course the script will never exit
now.
Is the only thing to do to to somehow get an expect method to somehow
wait for the end of the spawned program?