-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progress bar does not display correctly when redirecting output in any way #2582
Comments
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 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:
|
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:
|
@Andrew-J-Larson looks great! Now this is probably overkill, but I noticed a few details I missed before:
function 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... Before
-
\
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 After
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! |
WinGet output more cleaned up now, thanks to @asheroto in microsoft/winget-cli#2582 (comment)
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
The text was updated successfully, but these errors were encountered: