Alex Rivera | Logout

Why does my console application have command history?

Asked 2011-08-07T14:02:24.590
20

I have written a console application, which is essentially a Console.ReadLine()-Loop. When the application is waiting for input, pressing the up arrow key iterates through all previous lines of input. My application does not contain any code for this feature. What part of Windows provides this? How can I disable it?

I can only image that it's either a feature of the console subsystem or implemented in Console.ReadLine().

Here is some sample code that exhibits the described behavior:

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            do
            {
                input = System.Console.ReadLine();
            } while (input != "exit");
        }
    }
}

I would like to disable the history feature for now, and re-implement it later using my own code. The current behavior is too limited.

Edit
Report

1 Answer

0

Not tested, but it looks like passing an instance of CONSOLE_HISTORY_INFO to SetConsoleHistoryInfo with buffer size and count set to 1 would give the same control as the console window properties dialogue.

P/Invoke definitions at pinvoke.net

Also note this requires Windows V6 or later (ie. Vista/2008/7/2008R2).

answered 2011-08-07T14:16:28.790

Your Answer