我在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