Open MarcoPeraza opened 2 years ago
The same issue also occurs with winget -list - not just related to the install packages.
[Policy] Area-Output
Same issue for upgrade as well, very annoying to work with.
Here is the workaround I came up with. Not perfect, but it works until the spinner / progress bar can be turned off.
This method streams output in real-time, eliminating the wait to view results until after command completion.
function Strip-Progress {
param(
[ScriptBlock]$ScriptBlock
)
# regex pattern to match spinner characters and progress bar patterns
$pattern = 'Γû[Æê]|[-\\|/]'
# Execute the script block and process its output
& $ScriptBlock 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
# Output error records
"ERROR: $($_.Exception.Message)"
} elseif ($_ -notmatch '^\s*$') {
# Process non-empty lines
$line = $_ -replace $pattern, ''
if (-not [string]::IsNullOrWhiteSpace($line)) {
$line
}
}
}
}
Usage with Microsoft.WindowsTerminal
:
PS C:\Users\Administrator\desktop> Strip-Progress -ScriptBlock { winget install Microsoft.WindowsTerminal --accept-package-agreements --accept-source-agreements --force|tee output.txt }
Found Windows Terminal [Microsoft.WindowsTerminal] Version 1.19.10302.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, thirdparty packages.
This package requires the following dependencies:
Packages
Microsoft.UI.Xaml.2.8 [>= 8.2306.22001.0]
Successfully verified installer hash
Starting package install...
2%
2%
48%
95%
95%
95%
97%
97%
100%
Successfully installed
PS C:\Users\Administrator\desktop>
Issue related to feature request on issue #3494.
@asheroto, nicely done, I think I know one little thing to make it better (removes just the spinner symbols rather than the spinner symbols located everywhere):
$pattern = 'Γû[Æê]|^\s+[-\\|/]\s+$'
And here's how that looks now when updating GIMP:
PS C:\Users\Andrew> Strip-Progress -ScriptBlock { winget update GIMP.GIMP --accept-package-agreements --accept-source-agreements --force }
Found GIMP [GIMP.GIMP] Version 2.10.36
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://download.gimp.org/gimp/v2.10/windows/gimp-2.10.36-setup.exe
1024 KB / 305 MB
13.0 MB / 305 MB
23.0 MB / 305 MB
33.0 MB / 305 MB
43.0 MB / 305 MB
53.0 MB / 305 MB
64.0 MB / 305 MB
75.0 MB / 305 MB
86.0 MB / 305 MB
97.0 MB / 305 MB
106 MB / 305 MB
112 MB / 305 MB
122 MB / 305 MB
132 MB / 305 MB
142 MB / 305 MB
153 MB / 305 MB
164 MB / 305 MB
173 MB / 305 MB
183 MB / 305 MB
194 MB / 305 MB
205 MB / 305 MB
215 MB / 305 MB
225 MB / 305 MB
236 MB / 305 MB
247 MB / 305 MB
258 MB / 305 MB
269 MB / 305 MB
279 MB / 305 MB
288 MB / 305 MB
297 MB / 305 MB
305 MB / 305 MB
305 MB / 305 MB
Successfully verified installer hash
Starting package install...
Successfully installed
Here's the code with the modification I made + an additional one that retains newlines (except the beginning ones:
function Strip-Progress {
param(
[ScriptBlock]$ScriptBlock
)
# regex pattern to match spinner characters and progress bar patterns
$pattern = 'Γû[Æê]|^\s+[-\\|/]\s+$'
$firstTextLinePast = $false # skips over empty lines that start the output
# Execute the script block and process its output
& $ScriptBlock 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
# Output error records
"ERROR: $($_.Exception.Message)"
} elseif ($_ -notmatch '^\s*$') {
# Process non-empty lines
$line = $_ -replace $pattern, ''
if (-not [string]::IsNullOrWhiteSpace($line)) {
$firstTextLinePast = $true
$line
}
} elseif ($firstTextLinePast) {
# don't forget to put original empty lines back in
Write-Host
}
}
}
Which results in output like this:
PS C:\Users\Andrew> Strip-Progress -ScriptBlock { winget update }
Name Id Version Available Source
-----------------------------------------------------------------------------------------------------------------------
Google Chrome Google.Chrome 121.0.6167.162 122.0.6261.39 winget
Dev Home Microsoft.DevHome 0.1000.389.0 0.1001.389.0 winget
Microsoft 365 Apps for enterprise - en-us Microsoft.Office 16.0.17029.20140 16.0.17126.20132 winget
Microsoft Windows Desktop Runtime - 7.0.15 … Microsoft.DotNet.DesktopRuntime.7 7.0.15 7.0.16 winget
RealVNC Viewer 7.6.1 RealVNC.VNCViewer 7.6.1.50931 7.8.0 winget
Microsoft Windows Desktop Runtime - 6.0.26 … Microsoft.DotNet.DesktopRuntime.6 6.0.26 6.0.27 winget
7 upgrades available.
The following packages have an upgrade available, but require explicit targeting for upgrade:
Name Id Version Available Source
-----------------------------------------------------------------------------------
Teams Machine-Wide Installer Microsoft.Teams 1.6.0.4472 23320.3027.2591.1505 winget
@Andrew-J-Larson looks great!
Now this is probably overkill, but I noticed a few details I missed before:
269 MB / 305 MB
). Added another regex pattern to detect the download progress pattern and reformat it. I don't think it will cause any issues with non-winget-related text, as I doubt anyone would want two spaces after a slash in the pattern defined in the code even unrelated to winget. This particular code looks for two decimal points, although that might need to be changed; I didn't want to sway too far away and match unnecessary text.Write-Host
because it could break the output pipeline with certain commands, as it's intended for use to write to the host window itself, not necessarily the output stream. More infofunction Strip-Progress {
param(
[ScriptBlock]$ScriptBlock
)
# Regex pattern to match spinner characters and progress bar patterns
$progressPattern = 'Γû[Æê]|^\s+[-\\|/]\s+$'
# Corrected regex pattern for size formatting, ensuring proper capture groups are utilized
$sizePattern = '(\d+(\.\d{1,2})?)\s+(B|KB|MB|GB|TB|PB) /\s+(\d+(\.\d{1,2})?)\s+(B|KB|MB|GB|TB|PB)'
$previousLineWasEmpty = $false # Track if the previous line was empty
& $ScriptBlock 2>&1 | ForEach-Object {
if ($_ -is [System.Management.Automation.ErrorRecord]) {
"ERROR: $($_.Exception.Message)"
} elseif ($_ -match '^\s*$') {
if (-not $previousLineWasEmpty) {
Write-Output ""
$previousLineWasEmpty = $true
}
} else {
$line = $_ -replace $progressPattern, '' -replace $sizePattern, '$1 $3 / $4 $6'
if (-not [string]::IsNullOrWhiteSpace($line)) {
$previousLineWasEmpty = $false
$line
}
}
}
}
Using this code and your command usage...
```powershell - \ Found GIMP [GIMP.GIMP] Version 2.10.36 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://download.gimp.org/gimp/v2.10/windows/gimp-2.10.36-setup.exe - \ | / ΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 3.00 MB / 305 MB ΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 10.0 MB / 305 MB ΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 24.0 MB / 305 MB ΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 40.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 52.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 59.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 60.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 68.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 76.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 84.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 95.0 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 104 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 115 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 122 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 136 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 145 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 156 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 169 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 178 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 192 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 203 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 214 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 224 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 231 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 240 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆΓûÆ 247 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆΓûÆ 255 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆΓûÆ 265 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆ 275 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆΓûÆΓûÆ 284 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûÆ 295 MB / 305 MB ΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûêΓûê 305 MB / 305 MB Successfully verified installer hash Starting package install... - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ | / - \ Successfully installed ```
```powershell PS C:\Users\Administrator\desktop> Strip-Progress -ScriptBlock { winget install GIMP.GIMP --accept-package-agreements --accept-source-agreements --force | tee output.txt } Found GIMP [GIMP.GIMP] Version 2.10.36 This application is licensed to you by its owner. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages. Downloading https://download.gimp.org/gimp/v2.10/windows/gimp-2.10.36-setup.exe 0.00 B / 305 MB 9.00 MB / 305 MB 16.0 MB / 305 MB 26.0 MB / 305 MB 38.0 MB / 305 MB 47.0 MB / 305 MB 54.0 MB / 305 MB 62.0 MB / 305 MB 74.0 MB / 305 MB 83.0 MB / 305 MB 92.0 MB / 305 MB 100 MB / 305 MB 109 MB / 305 MB 118 MB / 305 MB 128 MB / 305 MB 139 MB / 305 MB 150 MB / 305 MB 157 MB / 305 MB 165 MB / 305 MB 174 MB / 305 MB 180 MB / 305 MB 188 MB / 305 MB 198 MB / 305 MB 210 MB / 305 MB 224 MB / 305 MB 238 MB / 305 MB 245 MB / 305 MB 255 MB / 305 MB 261 MB / 305 MB 268 MB / 305 MB 274 MB / 305 MB 283 MB / 305 MB 294 MB / 305 MB 304 MB / 305 MB 305 MB / 305 MB Successfully verified installer hash Starting package install... Successfully installed PS C:\Users\Administrator\desktop> ```
Thoughts?
Yeah now it's looking pretty great!
Brief description of your issue
winget progress bars become line noise when redirecting to a file (in either cmd.exe or powershell) or when piping to
tee
orout-default
(in powershell). I don't think there's a way to turn off the progress bar, so no way to avoid your terminal and log files getting spammed if you want to save output to a file.Winget's internal logging functionality is not a solution to this issue. Consider a script that does many things, where running winget is just a small part. You often want to capture the entire output of the script, including the winget output, into a single log file. Having separate logfiles for all winget invocations doesn't really allow that. I often redirect the output of large powershell programs, which might invoke dozens of other scripts and executables along the way.
I guess there's two related issues here:
Steps to reproduce
Expected behavior
A pretty progress bar in the terminal and/or log files without pages of gibberish.
Actual behavior
If you are downloading a large file and/or have a slow connection, you can easily have many tens or even hundreds of these lines.
Environment