Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Write-Host buffer error?

Reply
 
Old 3 Weeks Ago   #1 (permalink)
Martin Zugec


 
 

Write-Host buffer error?

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

My System SpecsSystem Spec
Old 3 Weeks Ago   #2 (permalink)
Guido


 
 

Re: Write-Host buffer error?

On 6 Nov., 10:47, Martin Zugec <martin.zu...@newsgroup> wrote:
Quote:

> Hi gents,
>
> Colleague of mine sent me small piece of code that was failing today.
.....
.....
Quote:

> 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
My System SpecsSystem Spec
Old 3 Weeks Ago   #3 (permalink)
Larry__Weiss


 
 

Re: Write-Host buffer error?

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


Martin Zugec wrote:
Quote:

> 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
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
write-host? no thanks PowerShell
When to use write-host? PowerShell
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? .NET General
Host buffer size setters don't work? PowerShell
[PS] write-host: "Not enough memory available for this cmd"/error PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46