我在linux上使用perl,我有2个设备 - 一个pc(linux盒子)和一个路由器/ dsl-thingy - 在我的本地网上ip地址192.168 .1.1 & 192.168.1.2并试图列出或显示ping的进度这样的+其他没有现有设备的测试,下面的代码,但我有我的StatusLabel更新的麻烦,任何帮助...从Perl中的线程更新标签
for($i=1;$i<=10;++$i) { # --- $i<$VarClients --- 254
my $thr_List = ("ping$i");
$thr_List = threads->create(\&pingingthreads, "$i");
}
sub pingingthreads{
my @pingpong = ping("$localAddress$i", '-c 1', '-i .2'); # -i may not count for much?
print "Pinging: $localAddress$i\n"; # output goes from address1 - address10 ok
$StatusLabel = "Pinging: $localAddress$i"; # only the last responding one(device) seems to be shown in my statuslabel?!
$val = ($val + 10); # 0.392156863
print "$val\% done...\n"; # goes to 100% for me ok
# $indicatorbar->value($val); # I have a ProgressBar and it gets stuck on 20% also
if ($val == 100){$val = 0;
} # reset after scanning
# then after the last ping, update the statusLable:
#my @ParamList = ('something', 'testing', 7, 8, 9);
#$thr5 = threads->create(\&updateStatusLable, @ParamList); # starting a thread within a thread ???
# ping response text...
for(@pingpong) { # need to do something for none responding clients & any time laps/ping latency..., or *** ???
$pong=$_;
chop ($pong); # Get rid of the trailling \n ??
if ($pong =~ m/1 packets transmitted, 1 received, 0% packet loss/) {
push(@boxs, "$localAddress$i");
} else{
# see the other lines from the ping's output
# print "$pong\n";
}
}
}
# For $localAddress$i icmp_seq=1 Destination Host Unreachable ???
--------------------- # StatusBar/progress label & bar ----------------
my $sb = $main->StatusBar();
$sb->addLabel(-textvariable => \$StatusLabel,
-relief => 'flat',
-font => $font,
-foreground => "$statusbartextColour",
);
my $indicatorbar = $sb->ProgressBar(-padx=>2, -pady=>2, -borderwidth=>2,
-troughcolor=>"$Colour2",
-colors=>[ 0, "$indicatorcolour" ],
-length=>106,
-relief => 'flat',
-value => "$val",
)->pack;
# $val = 0;
# $indicatorbar->value($val);
=====================================
my $StatusLabel :shared =();
my $val :shared = (0); # var for progress bar value
我在这里上传我的全部代码(http://cid-99cdb89630050fff.office.live.com/browse.aspx/.Public)如果需要的话,其在Boxy.zip ...
欢迎来到SO。 SO不是一个代码工厂。你需要提出具体的问题,你会得到具体的答案。 – musiKk
对不起,如果上述不正确,我的问题不同的是......我如何更新Perl中的线程标签。我正在使用上述只是为了显示我在哪里(只是在玩)。 – Carpenter