add print test page v3
This commit is contained in:
40
apply.pl
40
apply.pl
@@ -1605,33 +1605,39 @@ sub run_queue_test_command( @ )
|
||||
{
|
||||
my @cmd = @_;
|
||||
my $output = '';
|
||||
my $pid;
|
||||
my $tmpdir = '/run/mars-nwe-webui';
|
||||
my $out;
|
||||
my $rc;
|
||||
|
||||
$queue_test_command_rc = 0;
|
||||
|
||||
$pid = open( my $fh, '-|' );
|
||||
$tmpdir = '/tmp' if ! -d $tmpdir || ! -w $tmpdir;
|
||||
$out = $tmpdir . '/smart-test-print-output-' . $$ . '-' . int( rand( 1000000 ) ) . '.txt';
|
||||
|
||||
if( ! defined( $pid ) )
|
||||
$rc = system( @cmd, '>', $out, '2>&1' );
|
||||
|
||||
# system(@list) does not process shell redirection. If the platform did
|
||||
# not create an output file, fall back to a shell command with fully quoted
|
||||
# arguments only for capturing output.
|
||||
if( ! -e $out )
|
||||
{
|
||||
$queue_test_command_rc = 255 << 8;
|
||||
return 'could not fork for nprint: ' . $!;
|
||||
my $shell = join( ' ', map { queue_test_shell_log_quote( $_ ) } @cmd ) . ' > ' . queue_test_shell_log_quote( $out ) . ' 2>&1';
|
||||
$rc = system( $shell );
|
||||
}
|
||||
|
||||
if( $pid == 0 )
|
||||
{
|
||||
open( STDERR, '>&', STDOUT );
|
||||
exec( @cmd );
|
||||
print STDOUT 'could not exec ' . $cmd[0] . ': ' . $! . "\n";
|
||||
exit( 127 );
|
||||
}
|
||||
$queue_test_command_rc = $rc;
|
||||
|
||||
while( my $line = <$fh> )
|
||||
if( open( my $fh, '<', $out ) )
|
||||
{
|
||||
$output .= $line;
|
||||
local $/ = undef;
|
||||
$output = <$fh>;
|
||||
close( $fh );
|
||||
unlink( $out );
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = 'could not read nprint output file ' . $out . ': ' . $!;
|
||||
}
|
||||
|
||||
close( $fh );
|
||||
$queue_test_command_rc = $?;
|
||||
|
||||
$output = '' unless defined( $output );
|
||||
$output =~ s/\r//g;
|
||||
|
||||
Reference in New Issue
Block a user