diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2019-07-16 02:30:05 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2019-07-26 07:50:38 +0300 |
commit | 645bd71404dde95c0eb1679b798b4349fe8ceca4 (patch) | |
tree | 7d7f2c870e2ce25995af88df43861f2682cda0da /coin | |
parent | cb8d38fd9cbfc3c83efffba3fc2587378e9f7476 (diff) |
Provisioning: Run-Executable should print stdout and stderr to log
Task-number: QTQAINFRA-3085
Change-Id: I5343753f75157a2a894bb3ac50d416ab044d86fb
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'coin')
-rw-r--r-- | coin/provisioning/common/windows/helpers.ps1 | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/coin/provisioning/common/windows/helpers.ps1 b/coin/provisioning/common/windows/helpers.ps1 index 6e8e0365..ba35f6b5 100644 --- a/coin/provisioning/common/windows/helpers.ps1 +++ b/coin/provisioning/common/windows/helpers.ps1 @@ -22,14 +22,46 @@ function Run-Executable [string]$Executable=$(throw("You must specify a program to run.")), [string[]]$Arguments ) + + $stdoutFile = [System.IO.Path]::GetTempFileName() + $stderrFile = [System.IO.Path]::GetTempFileName() + if ([string]::IsNullOrEmpty($Arguments)) { Write-Host "Running `"$Executable`"" - $p = Start-Process -FilePath "$Executable" -Wait -PassThru + $p = Start-Process -FilePath "$Executable" -Wait -PassThru ` + -RedirectStandardOutput $stdoutFile -RedirectStandardError $stderrFile } else { Write-Host "Running `"$Executable`" with arguments `"$Arguments`"" - $p = Start-Process -FilePath "$Executable" -ArgumentList $Arguments -PassThru + $p = Start-Process -FilePath "$Executable" -ArgumentList $Arguments -PassThru ` + -RedirectStandardOutput $stdoutFile -RedirectStandardError $stderrFile Wait-Process -InputObject $p } + + $stdoutContent = [System.IO.File]::ReadAllText($stdoutFile) + $stderrContent = [System.IO.File]::ReadAllText($stderrFile) + Remove-Item -Path $stdoutFile, $stderrFile -Force -ErrorAction Ignore + + $hasOutput = $false + if ([string]::IsNullOrEmpty($stdoutContent) -eq $false -or [string]::IsNullOrEmpty($stderrContent) -eq $false) { + $hasOutput = $true + Write-Host + Write-Host "======================================================================" + } + if ([string]::IsNullOrEmpty($stdoutContent) -eq $false) { + Write-Host "stdout of `"$Executable`":" + Write-Host "======================================================================" + Write-Host $stdoutContent + Write-Host "======================================================================" + } + if ([string]::IsNullOrEmpty($stderrContent) -eq $false) { + Write-Host "stderr of `"$Executable`":" + Write-Host "======================================================================" + Write-Host $stderrContent + Write-Host "======================================================================" + } + if ($hasOutput) { + Write-Host + } if ($p.ExitCode -ne 0) { throw "Process $($Executable) exited with exit code $($p.ExitCode)" } |