如何清除批处理中的选定行而不是整个屏幕? [英] How to clear selected lines in Batch instead of the whole screen?
问题描述
当我们使用 pause
时,它显示按任意键继续...".按任意键后,后面的文字会保留下来,剩下的文字会出现在它的下方.如果我在 pause
之后使用 cls
整个屏幕被清除.
When we use the pause
it shows "Press any key to continue . . .". After pressing any key, the latter text remains, and the remaining text appears below it. If I use cls
after pause
the whole screen gets cleared.
有什么方法可以只删除按任意键继续......"按任意键后?另外,如何只清除选定的行而不是清除整个屏幕?
Is there any method to remove only "Press any key to continue . . ." after pressing any key? Also, how do I clear only selected lines instead of clearing the whole screen?
推荐答案
针对这个问题有多种解决方案,但批处理没有提供一个简单的解决方案.
There are multipe solutions for this problem, but batch doesn't offer a simple one.
批处理的主要问题是,您无法使用普通命令将光标向上移动.
The main problem of batch is, that you can't move the cursor up with normal commands.
1) 您可以使用 cls
来清除屏幕并重新绘制所有必要的数据.
1) You can use cls
to clear the screen and redraw all necessary data again.
2) 您可以使用外部程序来移动光标(该程序可以动态创建),例如 将光标移动到 0,0
2) You can use an external program to move the cursor (this programs can be created on the fly), like Move Cursor to 0,0
3) 你可以滥用 timeout
命令回到第二行 使用 TIMEOUT 命令将光标移动到屏幕主页!,Aacini
3) You can abuse the timeout
command to go back to the second line
Move cursor to screen home with TIMEOUT command!, a very cool trick discovered by Aacini
4) 在 Windows 10 中您可以使用 Ansi-Escape 序列来移动光标并获得许多其他效果,但它仅适用于 Win10
4) With Windows 10 you can use Ansi-Escape sequences to move the cursor and get many other effects, but it will work only for Win10
这篇关于如何清除批处理中的选定行而不是整个屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!