Hi,
I've been having trouble understanding why I'm not seeing the correct behavior when trying to use Gtk2::Helper/Glib::IO within a foreach loop.
I've searched and seen occurrences of this particular issue but seem to still have problems. I've tried both Gtk2::Helper/Glib::IO with the same results.
I want to run through the foreach loop and depending on the results of the current command I'm processing either stop completely or append information to the results.
It works great for the last member in the array but will not process the other members.
ENVIRONMENT
Red Hat EL 5.2
perl 5.8.8
Glib: 1.200
Glib 1.200
Gtk2 1.200
Glib built for 2.12.3, running with 2.12.3
Gtk2 built for 2.10.4, running
with 2.10.4
CODE THAT WORKS WITH LAST ARRAY MEMBER
# Watch the pipe and report back to the output window
sub buildWatcher2 {
my @buildCmds = @_;
our $buildFailed = FALSE;
our $fh;
#foreach (@buildCmds) {
foreach ('ls -la', 'du /usr/local') { # sample commands
if ($buildFailed) {
return;
}
open($fh, "$_ 2>&1 |") or die "\nFailed running subprocess";
our $tag = Glib::IO->add_watch(fileno($fh), ['in', 'hup'] => sub {
my ($fileno, $condition) = @_;
if ($condition >= 'in') {
$line = <$fh>;
$OutputBuffer->insert($OutputBuffer->get_end_iter,
$line);
$ReportBuffer->insert($ReportBuffer->get_end_iter, $line);
my $end_mark = $OutputBuffer->create_mark('end', $OutputBuffer->get_end_iter, FALSE);
$OutputTextView->scroll_to_mark($end_mark, 0.0, TRUE, 0.0, 1.0);
Gtk2->main_iteration while(Gtk2->events_pending);
if (($line =~ /cannot resolve symbol/) or ($line =~ /does not exist/)
or ($line =~ /BUILD
FAILED/)) {
$buildFailed = TRUE;
close($fh);
set_ui_waiting();
}
}
if ($condition >= 'hup') {
Glib::Source->remove($tag);
$widget->set_sensitive(TRUE);
close($fh);
$OutputBuffer->insert($OutputBuffer->get_end_iter, $line);
$ReportBuffer->insert($ReportBuffer->get_end_iter, $line);
my ($start, $end) = $ReportBuffer->get_bounds;
print ANT_REPORT ($ReportBuffer->get_text($start, $end, TRUE));
close(ANT_REPORT);
if ($buildFailed) {
pasLog("$buildTarget build failed");
pasStats("\tbuildFailed\t$buildTarget");
$statusbar->push($context_id, sprintf("$buildTarget build failed."));
} else {
pasLog("$buildTarget build
successful");
pasStats("\tbuildSuccessful\t$buildTarget");
$statusbar->push($context_id, sprintf("$buildTarget build successful."));
}
set_ui_waiting();
return FALSE;
}
return TRUE;
});
}
}
Thanks in advance for all the
help.
Michael