By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,507 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,507 IT Pros & Developers. It's quick & easy.

Redirect StdIO-Problem: Console.In.Peek() hungs !

P: n/a
Hi All !

I think, there is a bug in the System.Console class related to use the
STDIO streams. I am doing a very simple thing in a console-based program
named CS [ConsoleTest]

Console.In.Peek();

and the program hungs if no parameters were provided on the commandline.
If I use simple redirection like "echo "hallo" | cs.exe"
everything is fine.

I thing this is a bug in the console class. Because I am delaing with
different streams, I need to pass "TextReader" instances to a method
and have to expect, that it works with all types of TextReaders well.

I have urgent needs, because I have to distribute an I/O-filter
very quickly. I am MSDN Universal Abonnent and can require support!

Thanks so far and
best regards,
Manfred

Note:There was a similar request [perhabs from a person, which has
possibly no validity of claim], but no answer! The request was:
Subject: Redirection from stdin 3/7/2006 6:29 AM PST
By: Stefano Del Furia In: microsoft.public.dotnet.framework

May 6 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> I think, there is a bug in the System.Console class related to use the
STDIO streams. I am doing a very simple thing in a console-based program
named CS [ConsoleTest]

Console.In.Peek();

and the program hungs if no parameters were provided on the commandline.
If I use simple redirection like "echo "hallo" | cs.exe"
everything is fine.


Not sure, but I think the article at
http://msdn.microsoft.com/library/de...ui07152003.asp
might help.

Chris Jobson
May 6 '06 #2

P: n/a
Hi Chris and All!

Thanks a lot, I could'nt find this article!

Practically, I cannot accept this to be a solution: I always pass a
TextReader to a method and inside this method, I have to recognize, if the
stream is at the end or empty. The method cannot know, if this comes from
the Console.In TextReader. Wraping around the OS layer is one of the
requirements of the Framework.

I think, there were several bad decision while developing about the Console
class:Why should I assume, the TextReader to be already open? I checked the
Console.In to be null, but is'nt. Doing many things "automatically" presents
you problems on another end. In the FileStream class, ther is the Handle
property ....It looks like doing a Peek() opens the TextReader instead of
checking it.

Additionally, I have to run this proggi(s) also on some Unix machines and
using the W32 API would make it platform dependent and also "offers" me some
code maintenance nightmare.

Thanks a lot and
best regards,
Manfred

"Chris Jobson" <ch**********@btinternet.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I think, there is a bug in the System.Console class related to use the
STDIO streams. I am doing a very simple thing in a console-based program
named CS [ConsoleTest]

Console.In.Peek();

and the program hungs if no parameters were provided on the commandline.
If I use simple redirection like "echo "hallo" | cs.exe"
everything is fine.


Not sure, but I think the article at
http://msdn.microsoft.com/library/de...ui07152003.asp
might help.

Chris Jobson

May 6 '06 #3

P: n/a
<a@b> wrote in message news:eE**************@TK2MSFTNGP04.phx.gbl...
Hi Chris and All!

Thanks a lot, I could'nt find this article!

Practically, I cannot accept this to be a solution: I always pass a
TextReader to a method and inside this method, I have to recognize, if the
stream is at the end or empty. The method cannot know, if this comes from
the Console.In TextReader. Wraping around the OS layer is one of the
requirements of the Framework.
If you're checking whether the input is at the end/empty/etc, you might need
a Stream, not a TextReader. Can you use Console.OpenStandardInput() instead
of Console.In, which returns a Stream object and you can use CanRead, etc.?

I think, there were several bad decision while developing about the
Console class:Why should I assume, the TextReader to be already open? I
checked the Console.In to be null, but is'nt. Doing many things
"automatically" presents you problems on another end. In the FileStream
class, ther is the Handle property ....It looks like doing a Peek() opens
the TextReader instead of checking it.

Additionally, I have to run this proggi(s) also on some Unix machines and
using the W32 API would make it platform dependent and also "offers" me
some code maintenance nightmare.

Thanks a lot and
best regards,
Manfred

"Chris Jobson" <ch**********@btinternet.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I think, there is a bug in the System.Console class related to use the
STDIO streams. I am doing a very simple thing in a console-based program
named CS [ConsoleTest]

Console.In.Peek();

and the program hungs if no parameters were provided on the commandline.
If I use simple redirection like "echo "hallo" | cs.exe"
everything is fine.


Not sure, but I think the article at
http://msdn.microsoft.com/library/de...ui07152003.asp
might help.

Chris Jobson


May 12 '06 #4

P: n/a
Hello !

Thanks a lot for your investigation.
I came not onto this idea.
Sad to say, even this is not working.
The stream has no ".Peek()" method. Because the returned stream is not
seekable, it has
wether a position or a length :-( :-(

Thanks,
Manfred

"Ben Voigt" <rb*@nospam.nospam> wrote in message
news:eO**************@TK2MSFTNGP03.phx.gbl...
<a@b> wrote in message news:eE**************@TK2MSFTNGP04.phx.gbl...
Hi Chris and All!

Thanks a lot, I could'nt find this article!

Practically, I cannot accept this to be a solution: I always pass a
TextReader to a method and inside this method, I have to recognize, if
the stream is at the end or empty. The method cannot know, if this comes
from the Console.In TextReader. Wraping around the OS layer is one of the
requirements of the Framework.


If you're checking whether the input is at the end/empty/etc, you might
need a Stream, not a TextReader. Can you use Console.OpenStandardInput()
instead of Console.In, which returns a Stream object and you can use
CanRead, etc.?

I think, there were several bad decision while developing about the
Console class:Why should I assume, the TextReader to be already open? I
checked the Console.In to be null, but is'nt. Doing many things
"automatically" presents you problems on another end. In the FileStream
class, ther is the Handle property ....It looks like doing a Peek() opens
the TextReader instead of checking it.

Additionally, I have to run this proggi(s) also on some Unix machines and
using the W32 API would make it platform dependent and also "offers" me
some code maintenance nightmare.

Thanks a lot and
best regards,
Manfred

"Chris Jobson" <ch**********@btinternet.com> wrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
I think, there is a bug in the System.Console class related to use the
STDIO streams. I am doing a very simple thing in a console-based
program
named CS [ConsoleTest]

Console.In.Peek();

and the program hungs if no parameters were provided on the
commandline.
If I use simple redirection like "echo "hallo" | cs.exe"
everything is fine.

Not sure, but I think the article at
http://msdn.microsoft.com/library/de...ui07152003.asp
might help.

Chris Jobson



May 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.