Ich vermute, dass die Ausgabe des Kommandos gepuffert wird, bevor sie an die Variable @cmd gegeben wird.
Tritt nun der Alarm-Event auf, findet leider die Übergabe vom Puffer an die Variable nicht statt.
Daher enthält @cmd dann nicht die bisherigen Ausgaben.
EDIT:
Möglicher Workaround: Öffne Dein externes Kommando via Pipe und lese z.B. zeilenweise ein:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;
my $cmd = 'ping';
my $host = '127.0.0.1';
my $timeout = 3;
my @cmd = ( "no output yet" );
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
open my $pipe, '-|', "$cmd -c 5 $host"
or die "Could not open pipe: $!";
while ( my $line = <$pipe> ) {
push @cmd, $line;
}
close $pipe;
alarm 0;
};
if ($@) {
print "Output: @cmd\n";
print "timed out - $@\n";
warn unless $@ eq "alarm\n";
} else {
print "Output: @cmd\n";
print "No time out\n";
}
Last edited: 2015-03-11 16:58:17 +0100 (CET)
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!