是否可以通过编程方式清除控制台历史记录? [英] Is is possible to programmatically clear the console history?

查看:96
本文介绍了是否可以通过编程方式清除控制台历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用控制台应用程序时,将存储在 Console.ReadLine()中输入的所有内容的历史记录。当在控制台提示符下输入内容时,按上/下光标将滚动浏览此历史记录(可以通过按F7查看整个历史记录。)。

When working with a console application, a history of everything that has been entered at a Console.ReadLine() is stored. When at a console prompt to enter something, pressing the up/down cursor will scroll through this history (and the whole history can be viewed by pressing F7).

使用C# ,是否有办法禁用此行为或清除已输入内容的历史记录?

Using C#, is there are way to either disable this behaviour or clear the history of what has already been entered?

Console.Clear()不会清除历史记录,只会清除屏幕缓冲区。我想清除命令历史记录。

To clarify, Console.Clear() does not clear the history, only the screen buffer. I want to clear the command history.

编辑:尝试了几种建议的方法以及我自己的一些设计,最好的方法是ho1建议的方法。这并不理想,因为它会弹出另一个控制台窗口,但是会清除历史记录。

Having tried several of the suggested methods, as well as some of my own devising, the best approach is the one suggested by ho1. It is not ideal because it brings up another console window, but it does clear the history.

推荐答案

编辑:删除了不正确的答案(我对您要执行的操作感到困惑),并添加了另一个(希望)更好的答案。

Removed incorrect answer (I got confused about what you wanted to do) and added another (hopefully) better answer.

使用 FreeConsole ,然后使用 AllocConsole 。我以为那样就不会保留命令行历史记录。

It might be possible to do this by freeing the current console using FreeConsole and then allocating a new console using AllocConsole. I'd assume that it wouldn't keep the command line history then.

通常,如果您想使用.Net不支持的控制台进行操作,框架,此MSDN页面是一个不错的地方:控制台功能

In general, if you want to do things with the Console that's not supported by the .Net Framework, this MSDN page is a good place to look: Console Functions

这篇关于是否可以通过编程方式清除控制台历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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