}
else{
$OS = "WIN";
+ $ENV{"PRINTF_EXPONENT_DIGITS"} = "2";
}
###
# exec the command line
- ###
- $pid = open3(\*CHILD_IN, \*OUT, \*OUT, $cmd{'cmd'} );
+ ### $line =~ s/\r//g;
+
+ my $e = IO::File->new_tmpfile;
+ $e->autoflush(1);
+ local *E = $e;
+ $pid = open3(\*CHILD_IN, ">&E", ">&E", $cmd{'cmd'} );
# push all provided input to executing child
map { print CHILD_IN "$_\n" } @{$cmd{'in'}};
die "fork() failed: $!" unless defined $forked;
if ( $forked == 0 ) { # child
sleep $time_to_wait;
- kill(9, $pid);
+ kill(SIGKILL, $pid);
exit $time_to_wait;
}
}
+
+ # Cleanup the executing child, and kill the timeouter brother on need
+ $cmd{'return'} = 0 unless defined($cmd{'return'});
+ my $wantret;
+ if(defined($cmd{'expect'}) and ($cmd{'expect'} ne "")){
+ $wantret = "got signal $cmd{'expect'}";
+ }else{
+ $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
+ $exitcode= 41;
+ }
+ my $gotret;
+ waitpid ($pid, 0);
+ $gotret = exit_status($?);
+ seek($e,0,0);
# pop all output from executing child
my @got;
- while(defined(my $got=<OUT>)) {
+ while(defined(my $got=<$e>)) {
$got =~ s/\r//g;
$got =~ s/^( )*//g;
chomp $got;
}
}
}
- close OUT;
-
+
if ($cmd{'sort'}){
sub mysort{
$a cmp $b
@{$cmd{'out'}}=sort mysort @{$cmd{'out'}};
}
}
-
- # Cleanup the executing child, and kill the timeouter brother on need
- $cmd{'return'} = 0 unless defined($cmd{'return'});
- my $wantret;
- if(defined($cmd{'expect'}) and ($cmd{'expect'} ne "")){
- $wantret = "got signal $cmd{'expect'}";
- }else{
- $wantret = "returned code ".(defined($cmd{'return'})? $cmd{'return'} : 0);
- $exitcode= 41;
- }
- my $gotret;
- waitpid ($pid, 0);
- $gotret = exit_status($?);
+
#Did we timeout ? If yes, handle it. If not, kill the forked process.
if($timeout==-1 and $gotret eq "got signal SIGKILL"){
$line_num++;
chomp $line;
+ $line =~ s/\r//g;
print "[TESH/debug] $line_num: $line\n" if $opts{'debug'};
my $next;
# deal with line continuations
}
$cmd{'output ignore'} = 1;
}
- elsif($line =~ /^!\s*expect signal (\w*)$/) {#expect signal SIGABRT
+ elsif($line =~ /^!\s*expect signal (\w*)/) {#expect signal SIGABRT
if (defined($cmd{'cmd'})) {
exec_cmd(\%cmd);
%cmd = ();
die "[TESH/CRITICAL] parse error: $line\n";
}
if($forked){
- kill(9, $forked);
+ kill(SIGKILL, $forked);
$timeout=0;
}
if($forked){
- kill(9, $forked);
+ kill(SIGKILL, $forked);
$timeout=0;
}