Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Write-Host buffer error?

12 views
Skip to first unread message

Martin Zugec

unread,
Nov 6, 2009, 4:47:54 AM11/6/09
to
Hi gents,

Colleague of mine sent me small piece of code that was failing today.
Problem was that Write-Host returned error when string was too long. I
already run into that problem before, but I wanted to investigate
little bit and find where the limits are. To my surprise, results were
very interesting.

Can someone shed some light on this:
Write-Host $("a" * 32000) # display a character 32k times

It works on Windows 7, however doesn't on Windows 2008 (and I expected
it won't work in Windows XP neither).

Error message returned is following:
Write-host : The Win32 internal error "Not enough storage is available
to process this command" 0x8 occured when writing console output
buffer at current cursor position. Contact Microsoft Support Services.
At line:1 char:11
+ write-host <<<< $("a" * 32000)
+ CategoryInfo : WriteError: (:) [Write-Host],
HostException
+ FullyQualifiedErrorId : WriteConsole,
Microsoft.PowerShell.Commands.Write
HostCommand

It is problem with both (!) Powershell v1 and v2 on older OSs.

Some additional interesting details:
$("a" * 32000) works (without Write-Host)

Write-Host $("a" * 32000) # FAILS
Write-Host $("a" * 16000) # works
Write-Host $("a" * 32000) # WORKS again :)

I am just curious where this problem comes from - does anyone have
explanation? Also curious why last example work - is there some kind
of buffer for Write-Host that is expanded automatically???

Thanks,
Martin

Guido

unread,
Nov 6, 2009, 5:31:53 AM11/6/09
to
On 6 Nov., 10:47, Martin Zugec <martin.zu...@gmail.com> wrote:
> Hi gents,
>
> Colleague of mine sent me small piece of code that was failing today.
....
....

> Write-Host $("a" * 32000) # FAILS
> Write-Host $("a" * 16000) # works
> Write-Host $("a" * 32000) # WORKS again :)
>
> I am just curious where this problem comes from - does anyone have
> explanation? Also curious why last example work - is there some kind
> of buffer for Write-Host that is expanded automatically???
>
> Thanks,
> Martin

Hi Martin,

I just ran the command [ Write-Host $("a" * 32000) ] on different
platforms:

W2K8 x86: FAILS -> it will work after running write-host $("a" *
16000);write-host $("a" * 32000)
W2K8 x64: WORKS
W2K3 x86: FAILS -> it will work after running write-host $("a" *
16000);write-host $("a" * 32000)
WIN7 x86: WORKS
W2K8 R2: WORKS

greetings,
Guido

Larry__Weiss

unread,
Nov 6, 2009, 10:53:29 AM11/6/09
to
I can reproduce it with V2 CTP3 on XP.

Piping "a" * 32000 to Write-Host produces the same results.
"a"*32000 | Write-Host

But once you get it in the mood by executing
"a"*16000 | Write-Host
there doesn't seem to be any limit. Try for example
"a"*320000 | Write-Host
"a"*3200000 | Write-Host
"a"*32000000 | Write-Host

So, I don't think it a simple buffer allocation issue on choice of size,
but rather a logic path that gets taken if a buffer can't be allocated
past a certain size, and a bug that fails to use the fallback logic at first.

Just a guess!

- Larry

0 new messages