diff --git a/bleachbit.ps1 b/bleachbit.ps1 index 31365c1..19226b7 100644 --- a/bleachbit.ps1 +++ b/bleachbit.ps1 @@ -75,17 +75,33 @@ if (-not (Test-Path $exePath)) { # Run the cleanup command and capture output Write-Host "Running BleachBit cleanup..." +# Create temp files for output capture +$stdoutFile = "$InstallPath\bleachbit_stdout.txt" +$stderrFile = "$InstallPath\bleachbit_stderr.txt" + try { - # Use call operator (&) to capture output instead of Start-Process - $output = & $exePath --clean $CleanerArgs 2>&1 + $process = Start-Process -FilePath $exePath -ArgumentList "--clean $CleanerArgs" -NoNewWindow -Wait -PassThru -RedirectStandardOutput $stdoutFile -RedirectStandardError $stderrFile -ErrorAction Stop - # Convert output to string - $outputText = $output | Out-String + # Read the captured output + $outputText = "" + if (Test-Path $stdoutFile) { + $outputText = Get-Content -Path $stdoutFile -Raw -ErrorAction SilentlyContinue + } + if (Test-Path $stderrFile) { + $stderrText = Get-Content -Path $stderrFile -Raw -ErrorAction SilentlyContinue + if ($stderrText) { + $outputText += $stderrText + } + } Write-Host $outputText } catch { $outputText = "Error running BleachBit: $($_.Exception.Message)" Write-Host $outputText +} finally { + # Cleanup temp files + if (Test-Path $stdoutFile) { Remove-Item $stdoutFile -ErrorAction SilentlyContinue } + if (Test-Path $stderrFile) { Remove-Item $stderrFile -ErrorAction SilentlyContinue } } # Output JSON result