Thanks for your replies.
> Does it have to be a console app? - reacting to the keypress event
Yes it is just a filter app.
I think you CAN get keypress events in a Console app but
I don't think piped data would cause a keypress event and
the program will not be taking any Q&A user input.
The program will filter a stream of floating point numbers.
I wanted the user to be able to supply the stream either:
- piped in on the command line
. . eg: echo "1.2334 2.345 3.456 " | myprog
- or from a file supplied by user as arg[0]
If neither is supplied the prog will create it's own sample data.
I couldnt get anything out of "Console.OpenStandardInput().Length"
- //Console.WriteLine("Console.OpenStandardInput().Length= {0}",
-
// Console.OpenStandardInput().Length );
-
// exception: The stream does not support seeking (with or without piped data)
-
Here is an example of my novice level and the things I have tried:
- using System;
-
using System.Text; // for ReadKey()
-
using System.IO; // for StreamReader etc
-
-
class MyProg
-
{
-
static void Main(string[] args)
-
{
-
//string s1;
-
//int i;
-
char c;
-
-
Console.WriteLine("-----test-----");
-
-
/**** So far everything has blocked the same as Console.Read(): ****/
-
while( Console.In.Peek() != -1 ) // blocks at first read...
-
{
-
//s1 = Console.ReadLine();
-
//Console.Write(s1);
-
-
//i = Console.Read();
-
//Console.Write("{0} ", i);
-
-
c = (char)Console.Read();
-
Console.Write("{0} ", c);
-
-
//c = Console.ReadKey(); // even with: using System.Text; still gets:
-
// Error: System.Console' does not contain a definition for `ReadKey'
-
//Console.Write("{0} ", c);
-
}
-
/****/
-
-
/**** This works to read stdin but still blocks... * /
-
TextReader trIn = Console.In;
-
while( trIn.Peek() != -1 )
-
{
-
//Console.WriteLine("trIn.Length= {0} ", trIn.Length );
-
// `System.IO.TextReader' does not contain a definition for `Length'
-
c = (char)trIn.Read();
-
Console.Write("{0} ", c );
-
}
-
trIn.close();
-
/ ****/
-
-
/**** This works to read stdin but still blocks the same:
-
-
StreamReader srIn= new StreamReader(Console.OpenStandardInput());
-
while( srIn.Peek() != -1 )
-
{
-
//Console.WriteLine("srIn.Length= {0} ", srIn.Length );
-
// System.IO.StreamReader' does not contain a definition for `Length'
-
//
-
c = (char)srIn.Read();
-
Console.Write("{0} ", c);
-
if(c == 'x') break;
-
}
-
srIn.Close();
-
****/
-
-
/****
-
if( Console.In )
-
Error: Cannot implicitly convert type `System.Console.In' to `bool'
-
****
-
if( (bool)Console.In )
-
Error: Cannot convert type `System.Console.In' to `bool'
-
****
-
if( Console.In.Good ) // no member "Good"
-
Console.Write("Console.In ");
-
else
-
Console.Write("NO Console.In ");
-
****/
-
-
//Console.WriteLine("Console.In= {0}", Console.In );
-
// ouptput: Console.In= System.IO.SynchronizedReader
-
-
//Console.WriteLine("Console.OpenStandardInput().Length= {0}",
-
// Console.OpenStandardInput().Length );
-
// exception: The stream does not support seeking (with or without piped data)
-
-
//Console.WriteLine("Console.In.Length= {0}", Console.In.Length );
-
// error: System.IO.TextReader' does not contain a definition for `Length'
-
}
-
}
There are so many objects and methods in C# I get lost.
I had thought that this would be doable in C# but maybe not. (I wonder why not)
I guess I'll have to get user to indicate input method as a CL argument.
Thanks for the ideas, Howard