You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Get-ChildItem | Format-Wide -AutoSize | Out-String" can't work on Powershell 6.0.1 & 6.0.2 #6471
>$PSVersionTable
Name Value
---------
PSVersion 6.0.1
PSEdition Core
GitCommitId v6.0.1
OS Microsoft Windows 10.0.16299
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
>$PSVersionTable
Name Value
---------
PSVersion 6.0.2
PSEdition Core
GitCommitId v6.0.2
OS Linux 4.4.0-43-Microsoft #1-Microsoft Wed Dec...
Platform Unix
PSCompatibleVersions {1.0,2.0,3.0,4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
If no -AutoSize param, the result will be fine. And it works well in WindowsPowerShell 5.1 with or without -AutoSize param.
When specify Format-Wide -AutoSize parameter, display items per row is decided from output width.
In this case, output width is depend on Out-String -Width value.
When -Width parameter is not specified, int.MaxValue is adopted as output width.
(This behavior is from PowerShell Core 6.0. #5193)
When initializing WideOutputContext, itemsPerRow value(=items per row) reaches int.MaxValue.
Therefore, creation of the _buffer buffer fails, resulting in an error.
Activity
stknohg commentedon Mar 23, 2018
Hi, I found an another workaround.
Workaround
Specify
Out-String -Widthparameter explicitly and set the appropriate value.e.g.
Cause
When specify
Format-Wide -AutoSizeparameter, display items per row is decided from output width.In this case, output width is depend on
Out-String -Widthvalue.When
-Widthparameter is not specified,int.MaxValueis adopted as output width.(This behavior is from PowerShell Core 6.0. #5193)
When initializing
WideOutputContext,itemsPerRowvalue(=items per row) reachesint.MaxValue.Therefore, creation of the
_bufferbuffer fails, resulting in an error.PowerShell/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs
Lines 1135 to 1170 in 36b71ba
andot commentedon Mar 23, 2018
Thank you! Now on with Powershell 6.x, my lolcat Module can works well.
iSazonov commentedon Mar 24, 2018
Could we use
int.MaxValue-1as init value?stknohg commentedon Mar 24, 2018
Ilya (@iSazonov) No, but we can use
Console.WindowWidthsame asTableOutputContext.PowerShell/src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs
Lines 923 to 939 in 36b71ba