@@ -411,26 +411,16 @@ jobs:
411411 - name : Run install command script (Windows)
412412 if : runner.os == 'Windows'
413413 run : |
414- # Redirect all output to a file to capture it even when terminating errors occur
415- try {
416- & .\install_cmd.ps1 > install_output.txt 2>&1
417- $installSuccess = $true
418- } catch {
419- $installSuccess = $false
420- }
421-
422- # Read captured output from file
423- $installOutput = Get-Content install_output.txt -Raw -ErrorAction SilentlyContinue
424- if (-not $installOutput) {
425- $installOutput = "No output captured"
426- }
414+ # Run script in a separate PowerShell process to capture all output even when it errors
415+ $installOutput = powershell -File .\install_cmd.ps1 2>&1 | Out-String
416+ $installExitCode = $LASTEXITCODE
427417
428418 Write-Host "Install command output:"
429419 Write-Host $installOutput
430420 Write-Host $LastExitCode
431421 Write-Host $installSuccess
432422
433- if ($installSuccess ) {
423+ if ($installExitCode -eq 0 ) {
434424 Write-Host "Installation completed successfully"
435425 # Refresh PATH from registry to pick up newly installed chef-client
436426 $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
@@ -515,27 +505,14 @@ jobs:
515505 Get-Content install.ps1
516506 - name : Run install.ps1 script
517507 run : |
518- # Import the module
519- . .\install.ps1
520-
521- # Redirect all output to a file to capture it even when terminating errors occur
522- try {
523- install > install_output.txt 2>&1
524- $installSuccess = $true
525- } catch {
526- $installSuccess = $false
527- }
528-
529- # Read captured output from file
530- $installOutput = Get-Content install_output.txt -Raw -ErrorAction SilentlyContinue
531- if (-not $installOutput) {
532- $installOutput = "No output captured"
533- }
508+ # Run install function in a separate PowerShell process to capture all output
509+ $installOutput = powershell -Command "& { . .\install.ps1; install }" 2>&1 | Out-String
510+ $installExitCode = $LASTEXITCODE
534511
535512 Write-Host "Install command output:"
536513 Write-Host $installOutput
537514
538- if ($installSuccess ) {
515+ if ($installExitCode -eq 0 ) {
539516 Write-Host "Installation completed successfully"
540517 # Refresh PATH from registry to pick up newly installed chef-client
541518 $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
0 commit comments