Powershell: Write-Debug and Write-Progress

Created on 12 Mar 2020  ·  10Comments  ·  Source: PowerShell/PowerShell

The progressbar is not displayed, if the loop that writes the progressbar also writes any output, even debug output.

Steps to reproduce

$DebugPreference = "Continue"
$WarningPreference = "Continue"
$InformationPreference = "Continue"
foreach($element in (1..100)) {
  Write-Progress -Activity "Test" -Status "$element of 100" -PercentComplete $element
  Write-Debug $element
  # Write-Host $element
  # Write-Warning $element
  # Write-Information $element
  Start-Sleep -Seconds $element
}

Expected behavior

The progressbar as well as the other output are visible in the console.

Actual behavior

Only the console output is visible, the progressbar is not.

Environment data


Name                           Value
----                           -----
PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Linux 5.5.8-arch1-1 #1 SMP PREEMPT Fri, 06 Mar 2020 00:57:33 +0000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Area-Cmdlets-Utility Issue-Bug

Most helpful comment

Not 100% sure... But It's definitely not ready for prime time because it can't seem to render non-ASCII characters well and supports Windows Terminal quite poorly...

Out-ConsoleGridView is fine... It's external and not GA, but for PowerShell I don't think it's at the level it needs to be at.

Maybe in the future my team can help fund work to make gui.cs better but it's not a priority in the near future at this time from what I know

All 10 comments

Write-Progress behaves quite differently on Unix systems, by the looks of it. I can reproduce on my Catalina machine as well:

Name                           Value                                                                                    ----                           -----                                                                                    PSVersion                      7.0.0
PSEdition                      Core
GitCommitId                    7.0.0
OS                             Darwin 19.3.0 Darwin Kernel Version 19.3.0: Thu Jan  9 20:58:23 PST 2020; root:xnu-6153…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

It probably needs a rewrite to support anything other than Windows properly. 😕

Ok, if it needs a rewrite anyway, I'd just like to drop this link for some "visual" inspiration.
https://appliedgo.net/tui/

Applied Go
Beef up your Go console application with a Text-Based UI

I know @TylerLeonhardt has been working with the gui.cs project; perhaps he'd like to take a look at utilising some of that here. 😁

I see gui.cs support ProgressBar. We could use this but we need to approve from MSFT team /cc @SteveL-MSFT to include gui.cs in the repo.

That would be a pretty substantial effort to move to gui.cs for just progress bars. gui.cs operates on an alternative screen buffer so we'd need the output of the script (Write-Debug) and the progress bar to both be sent to this alternative screen buffer.

@TylerLeonhardt Can you share more info? PowerShell uses Windows specific console API on Windows and .Net Core console API on Unix. My understanding is that PowerShell does not use a screen buffer (only a buffer for progress bar on Windows).
So I guess we could integrate gui.cs in PowerShell conhost.

My understanding is that PowerShell does not use a screen buffer (only a buffer for progress bar on Windows).

This is correct. Today, PowerShell doesn't use a screen buffer... but introducing gui.cs to the mix would mean that a screen buffer would need to be used since gui.cs only knows how to write into a screen buffer and that's the only way to have full control of the what is rendered in the terminal window on non-Windows.

@TylerLeonhardt Thanks! I also guess that PowerShell have only one method to write to screen so we could easily switch to gui.cs API. Only concern I have is how formatting (Format-Table) and coloring (Select-String) will work.
Opsss... Do you know that gui.cs support a tty output mode?

Not 100% sure... But It's definitely not ready for prime time because it can't seem to render non-ASCII characters well and supports Windows Terminal quite poorly...

Out-ConsoleGridView is fine... It's external and not GA, but for PowerShell I don't think it's at the level it needs to be at.

Maybe in the future my team can help fund work to make gui.cs better but it's not a priority in the near future at this time from what I know

I have the same issue, what i'm observing is that the progress bar is clearing up multiple lines, even those lines that don't belong to it.

$DebugPreference = "Continue"
$WarningPreference = "Continue"
$InformationPreference = "Continue"
foreach($element in (1..100)) {
  write-error "error is written"
  write-verbose "verbose is written"
  write-output "output is written"
  write-host "host is written"
  Write-Progress -Activity "Test" -Status "$element of 100" -PercentComplete $element
  Write-Debug $element
  # Write-Host $element
  # Write-Warning $element
  # Write-Information $element
  Start-Sleep -Seconds $element
} *>&1

as you see, all the write-output and write-host are missing. verbose either before the error and after the error is missing

image

OS: Ubuntu 18.0
Powershell 7.0

Was this page helpful?
0 / 5 - 0 ratings