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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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/default.asp?url=/archive/en-us/dnaraskdr/html/askgui07152003.asp
might help.

Chris Jobson
 
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 said:
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/default.asp?url=/archive/en-us/dnaraskdr/html/askgui07152003.asp
might help.

Chris Jobson
 
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 said:
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/default.asp?url=/archive/en-us/dnaraskdr/html/askgui07152003.asp
might help.

Chris Jobson
 
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 said:
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 said:
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/default.asp?url=/archive/en-us/dnaraskdr/html/askgui07152003.asp
might help.

Chris Jobson
 
Back
Top