W
William Stacey [MVP]
Trying to test a simple console app that reads from standard in if you pipe
input into it like:
"c:\ type config.txt | consoleinput.exe"
Seem to run into an issue. It seems like if you use a pipe, you can read
all the input lines fine until eof. However, if you need to then prompt for
input, the pipe is still hooked up so Read or ReadLine returns with -1 or
null after that point. So you can't prompt for "Hit a key to continue",
etc. I am guessing I need to somehow disconnect the pipe from stdin or
"refresh" the stdin stream so it again starts waiting for normal console
input. Have tried various things, but can't seem to again get normal Read
or Readline behavior. Any thoughts? TIA
== Test Method called from Main ===
static void ReadStdIn()
{
string line;
ArrayList al = new ArrayList(200);
while ( (line = Console.ReadLine()) != null )
{
al.Add(line);
}
string s = Console.ReadLine();
if ( s == null )
Console.WriteLine("Input is null.");
else
Console.WriteLine("Input is:" + s);
}
input into it like:
"c:\ type config.txt | consoleinput.exe"
Seem to run into an issue. It seems like if you use a pipe, you can read
all the input lines fine until eof. However, if you need to then prompt for
input, the pipe is still hooked up so Read or ReadLine returns with -1 or
null after that point. So you can't prompt for "Hit a key to continue",
etc. I am guessing I need to somehow disconnect the pipe from stdin or
"refresh" the stdin stream so it again starts waiting for normal console
input. Have tried various things, but can't seem to again get normal Read
or Readline behavior. Any thoughts? TIA
== Test Method called from Main ===
static void ReadStdIn()
{
string line;
ArrayList al = new ArrayList(200);
while ( (line = Console.ReadLine()) != null )
{
al.Add(line);
}
string s = Console.ReadLine();
if ( s == null )
Console.WriteLine("Input is null.");
else
Console.WriteLine("Input is:" + s);
}