From: <ro...@en...> - 2002-11-24 14:15:43
|
Hi I use some ugly code and I am investigating whether I can "clean it up" with modules and the new threading support in perl. Is Expect.pm a thread-safe module? If it is I must be doing something wrong, because I cannot even get the *basics* working. I apologize for posting multiple lines of code, but I am doing my best to keep it short. The following code works fine - no problems: ---- #!/usr/local/perli-5.8.0/bin/perl use strict; use threads; use Expect; sub mysub { my $remoteshell; unless ( $remoteshell = Expect -> spawn ("ssh2 192.168.1.1") ) { die "error spawning"; } $remoteshell -> log_stdout(1); unless ( $remoteshell -> expect (120, [ "ssword:" => sub { $remoteshell -> send ("mypassword\n"); } ], ) ) { die "no password prompt"; } unless ( $remoteshell -> expect (20,"ro\@charon:") ) { die "no prompt"; } print $remoteshell "touch /tmp/hopo\n"; $remoteshell ->soft_close(); } &mysub; ---- However, if I replace the call to mysub with the following: my $h = threads->new(\&mysub); $h->join; The program dies instantly with the error: thread failed to start: no password prompt at ./expect.pl line 21. From the processlist I can see that an ssh2 is launched, but the calling program does not even wait the 120 second timeout before dieing with the above error. If anyone can offer any advice to solve this I would be most grateful. Thanks, Rohit Kumar Mehta |