STDIN (console) input buffer limit = 256?

W

wizofaus

Hi,

If I write the following unmanaged C program:

main()
{
char buffer[1000];
gets(buffer);
}

I can type in pretty any length string at all (buffer overflow aside).

But if I try in managed C++ (or C#),

Console::ReadLine();

I can only type in 254 characters, allowing I imagine 2 for the
necessary CRLF.

I've even tried creating a FileStream on the handle from
GetStdHandle(STD_INPUT_HANDLE), but I get the same problem (which
really surprises me).
The only way I can read more from .NET is use ReadConsole directly.

Any clues why, and is there a way to change this behaviour? I need to
be able to enter much longer lines than 256 characters into my console
app.

Thanks
 
M

Michael D. Ober

What OS and command shell? MS-DOS and its derivatives (including the
command.com shell) had a limit of 254 characters. NT 4's and its
descendents cmd.exe shell has a much longer limit (I haven't reached it
yet.)

Mike.
 
W

wizofaus

Michael said:
What OS and command shell? MS-DOS and its derivatives (including the
command.com shell) had a limit of 254 characters. NT 4's and its
descendents cmd.exe shell has a much longer limit (I haven't reached it
yet.)

Mike.
Cmd.exe (XP Pro) - otherwise the unmanaged version would presumably
have the same problem.

BTW, is top-posting really the norm in m.p.dotnet.*?
Hi,

If I write the following unmanaged C program:

main()
{
char buffer[1000];
gets(buffer);
}

I can type in pretty any length string at all (buffer overflow aside).

But if I try in managed C++ (or C#),

Console::ReadLine();

I can only type in 254 characters, allowing I imagine 2 for the
necessary CRLF.

I've even tried creating a FileStream on the handle from
GetStdHandle(STD_INPUT_HANDLE), but I get the same problem (which
really surprises me).
The only way I can read more from .NET is use ReadConsole directly.

Any clues why, and is there a way to change this behaviour? I need to
be able to enter much longer lines than 256 characters into my console
app.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top