Jak mogę odczytać dane wyjściowe z zewnętrznych poleceń w czasie rzeczywistym w Perlu?
Mam kilka skryptów bashowych, które uruchamiam, ale ich ukończenie może potrwać kilka godzin, w tym czasie wypluwają prędkości pobierania, ETA i podobne informacje. Muszę przechwycić te informacje w perlu, ale napotykam na problem, nie mogę odczytać wyniku po wierszu (chyba, że czegoś mi brakuje).
Jakaś pomoc w rozwiązaniu tego problemu?
EDYTUJ: aby wyjaśnić to trochę lepiej, uruchamiam kilka skryptów bash obok siebie, chcę użyć gtk z perlem do tworzenia poręcznych pasków postępu. Obecnie używam 2 wątków dla każdego skryptu bash, który chcę uruchomić, jednego głównego wątku do aktualizacji informacji graficznych. Wygląda to mniej więcej tak, jak to możliwe:
my $command1 = threads->create(\&runCmd, './bash1', \@out1);
my $controll1 = threads->create(\&monitor, $command1, \@out1);
my $command1 = threads->create(\&runCmd, 'bash2', \@out2);
my $controll2 = threads->create(\&monitor, $command2, \@out2);
sub runCmd{
my $cmd = shift;
my @bso = shift;
@bso = `$cmd`
}
sub monitor{
my $thrd = shift;
my @bso = shift;
my $line;
while($thrd->is_running()){
while($line = shift(@bso)){
## I check the line and do things with it here
}
## update anything the script doesn't tell me here.
sleep 1;# don't cripple the system polling data.
}
## thread quit, so we remove the status bar and check if another script is in the queue, I'm omitting this here.
}