1
0
mirror of synced 2026-04-15 23:51:03 +00:00

Save the exit code of a command, but also allow its output to be saved to the log as it happens

This commit is contained in:
Axel Beckert
2010-05-17 02:16:44 +02:00
parent 620148b782
commit 8df98d4198

View File

@@ -3723,18 +3723,27 @@ sub runCommand
#
# Run it.
#
my $output = `$cmd`;
my $rc = $?;
my $rcopen = open(CMD, '-|', $cmd);
if (!defined($rcopen)) {
logprint("Starting command '$cmd' failed: $!\n");
logprint("Aborting\n");
print "See /var/log/xen-tools/$CONFIG{'hostname'}.log for details\n";
$FAIL = 1;
exit 127;
}
logprint($output);
while (my $line = <CMD>) {
logonly $line;
}
my $rcclose = close(CMD);
$CONFIG{ 'verbose' } && print "Finished : $cmd\n";
if ( $rc != 0 )
if (!$rcclose)
{
logprint("Running command '$cmd' failed.\n");
logprint("Running command '$cmd' failed with exit code $?.\n");
logprint("Aborting\n");
print "Running command '$cmd' failed.\n";
print "See /var/log/xen-tools/$CONFIG{'hostname'}.log for details\n";
$FAIL = 1;
exit 127;