[Ubuntu] Add verbosity during software report generation (#4811)

* Add verbosity during software report generation

* Fix Get-CpanVersion

* set default ValidateExitCode value to $true

* update java test

* use lower-case for parameters
This commit is contained in:
Aleksandr Chebotov
2021-12-28 11:16:20 +03:00
committed by GitHub
parent bb56fb7ef4
commit 92eeb55189
8 changed files with 107 additions and 44 deletions

View File

@@ -2,11 +2,27 @@ function Get-CommandResult {
param (
[Parameter(Mandatory=$true)]
[string] $Command,
[switch] $Multiline
[int[]] $ExpectExitCode = 0,
[switch] $Multiline,
[bool] $ValidateExitCode = $true
)
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
$stdout = & bash -c "$Command 2>&1"
$exitCode = $LASTEXITCODE
if ($ValidateExitCode) {
if ($ExpectExitCode -notcontains $exitCode) {
try {
throw "StdOut: '$stdout' ExitCode: '$exitCode'"
} catch {
Write-Host $_.Exception.Message
Write-Host $_.ScriptStackTrace
exit $LASTEXITCODE
}
}
}
return @{
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
ExitCode = $exitCode