0

我编写了一个脚本来连接到主机系统并使用 Win32::GUI 模块运行一些命令来输入命令。

在进行过程中,GUI 会冻结并且在完成之前没有响应。

谁能告诉我如何为这种情况实现线程。

4

1 回答 1

0
use strict;

use warnings;use Net::Telnet; use Win32::API; use Win32::GUI();

my $main = Win32::GUI::Window->new(
  -name => 'Main',
  -width => 500,
  -height => 900,
  -text => 'Perl',
  -minsize => 500, 900,
  );

my $font = Win32::GUI::Font->new( -name => "Comic Sans MS", -size => 8,);
$main->AddLabel(-text => "Welcome ", -pos  => [ 10, 10 ],);
$main->AddLabel(-text => "Enter Host Name / IP : ", -pos  => [ 10, 33 ],  );
my $t= $main->AddTextfield( -name => 'tfResults', -text => "", -pos  => [ 125, 30 ],  -size => [ 100, 25 ], -tabstop => 1, );
my $my_but = $main->AddButton(-text => "Submit",-name => 'btQuery', -pos  => [ 235, 30 ],-size => [ 50, 25 ],);
$main->Show(); 
Win32::GUI::Dialog();

sub btQuery_Click 
{

  my $txt1=$t->Text;  
  my $telnet = new Net::Telnet (   Timeout=>1800,    Errmode=>'die',    ); 
  chomp $txt1; 
  $telnet->open($txt1);

  $telnet->waitfor('/login: $/i');
  $telnet->print('root');
  $telnet->waitfor('/Password: $/i');
  $telnet->print('dangerous');
  $telnet->waitfor('/# $/i');
  print "\nConnected to host :$txt1 ";

  $main->AddLabel(-text => " Enter custom cmd:",-pos => 100, 100 ,-size => 250, 125 ,);
  my $t1= $main->AddTextfield(-name => 'tfResults2',-text => "",-pos => 130, 100 ,-size => 100, 25 ,);
  my $submit=$main->AddButton(-text => "Submit",-name => 'Unix_submit',-pos => 250, 100 ,-size => 50, 25 ,);



sub Unix_submit_Click { }

   } `
于 2013-04-02T10:36:51.083 回答