为什么我的控制台应用程序有命令历史记录? [英] Why does my console application have command history?

查看:476
本文介绍了为什么我的控制台应用程序有命令历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个控制台应用程序,它本质上是一个到Console.ReadLine() - 环。当应用程序等待输入,pressing通过输入的所有previous线向上箭头键进行迭代。我的应用程序不包含任何$ C $下此功能。什么Windows的一部分提供呢?如何禁用呢?

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?

我只能像它的控制台子系统中的一个或一特征到Console.ReadLine()。执行

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

下面是一些示例code表现出描述的行为:

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");
        }
    }
}

我想禁用历史记录功能,就目前而言,并重新实现它以后用我自己的code。目前的行为是太有限了。

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.

推荐答案

您可以通过编程调用 SetConsoleHistoryInfo 与正确设置 CONSOLE_HISTORY_INFO 结构......似乎没有管理类/方法,所以你将不得不使用的DllImport

you can change this behaviour of windows programmatically by calling SetConsoleHistoryInfo with a correctly setup CONSOLE_HISTORY_INFO structure... there seems to be no managed class/method so you will have to use DllImport etc.

<一个href="http://msdn.microsoft.com/en-us/library/ms686031%28v=VS.85%29.aspx">http://msdn.microsoft.com/en-us/library/ms686031%28v=VS.85%29.aspx
<一href="http://msdn.microsoft.com/en-us/library/ms682077%28v=VS.85%29.aspx">http://msdn.microsoft.com/en-us/library/ms682077%28v=VS.85%29.aspx

http://msdn.microsoft.com/en-us/library/ms686031%28v=VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms682077%28v=VS.85%29.aspx

如果需要的话 - 控制台等几个方面,可以在托管的方式进行处理 - 看的 C#控制台,Console.Clear问题

IF need be - several other aspects of the console can be handled in a managed way - see c# console, Console.Clear problem

这篇关于为什么我的控制台应用程序有命令历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆