I am trying to write a console program similar to "less", where I can pipe data in to it from the command line, and then interact with that data via the keyboard.
I am running in to the following exception: Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
The suggested Console.Read
appears to be reading from the pipe instead of the console, so that doesn't work for me.
I understand that I can not Console.ReadKey
while Console.IsInputRedirected
, but I believe there has to be some work around because programs such as less
accomplishes the same goal.
Does anyone know how I can Console.ReadKey
(or equivalent) when the standard input has been redirected?
I've already looked in to this article, but it doesn't appear to work. The call to AttachConsole
returns false, and the console application terminates.