From: Roland G. <rgi...@cp...> - 2007-07-13 16:16:54
|
>From the perlthrtut: "Thinking of mixing fork() and threads? Please lie down and wait until the feeling passes." ;-) Note that spawn() does a fork. So this can only work if you spawn() all SSH connections in the main thread and then pass the Expect objects to the threads for handling. Bryan Bueter has provided a working example for using Expect/SSH/threads on the mailing list. Hope this helps, Roland PS: Net::SSH2 looks promising because it's objects are tied filehandles and thus should work with Expect via exp_init(). But I haven't had the time to try that yet. Hopefully any day soon... On 7/11/07, schlum <jsc...@bo...> wrote: > > Hi, > > I spent few days on this one, but couldn't get it working... > > I am working under sunOS > bt1wxxxx#uname -a > SunOS bt1wxxxx 5.6 Generic_105181-23 sun4u sparc SUNW,Ultra-60 > > I can run the following script without any problem : > > #!/usr/bin/perl > use strict; > use Expect; > my $exp = Expect->new; > $exp->raw_pty(1); > my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') or > die "Cannot spawn command: $!\n"; > my @test1 = $exp->expect(5,'-re','password:'); > $exp->clear_accum(); > my @test2 = $exp->send("my_pass\r\n"); > my @test3 = $exp->expect(15,'-re','my_host'); > my @test4 = $exp->send("sh privilege\r\n"); > > The last command is exectuted successfuly. > > But if I try this : > > #!/usr/bin/perl > use strict; > use Expect; > use threads; > use threads::shared; > use Thread::Queue::Any; > > my $thread = threads->new(\&threadJob,); > $thread->join; > > sub threadJob{ > my $exp = Expect->new; > $exp->raw_pty(1); > my $test = $exp->spawn('/usr/local/bin/ssh', -l => 'my_user', 'my_host') > or die "Cannot spawn command: $!\n"; > my @test1 = $exp->expect(5,'-re','password:'); > $exp->clear_accum(); > my @test2 = $exp->send("my_pass\r\n"); > my @test3 = $exp->expect(15,'-re','my_host'); > my @test4 = $exp->send("sh privilege\r\n");# On envoie le mdp > } > > I actually get connected, but Expect don't interact anymore with ssh after > the logging. Instead, I can access the box, I telneted from STDIN ... > > Does anybody knows why I'm getting this strange behavior ? > > Btw, when I close the conection, the script finishes to run peacefully. > > -- > View this message in context: http://www.nabble.com/Trouble-with-Expect-working-with-Threads-tf4062209.html#a11541250 > Sent from the Perl - Expectperl-Discuss mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |