问题
I want to write a Powershell script that shows a few lines (maybe 5), but they stay in the same spot/position in the terminal window. For example: If I was writing a script that printed if a few devices were pingable, I wouldn't want the output to keep scrolling down the terminal; I would want each line to stay in the position they are in, but update over time.
Ex:
+----------------------+ +----------------------+
| TERMINAL | | TERMINAL |
+----------------------+ +----------------------+
| Device1: PINGABLE | | Device1: NOT PINGABLE|
| Device2: NOT PINGABLE| | Device2: NOT PINGABLE|
| | | |
| | | |
| | | |
| | | |
+----------------------+ +----------------------+
The script continues to run, the lines stay in the same place, and the output updates if necessary. How could I implement this in Powershell?
I just found this forum post that outlines my question more clearly: http://www.minasi.com/forum/topic.asp?TOPIC_ID=29171
Is this still the case? Is it still not possible?
回答1:
Take a look at $host.UI.RawUI
and specifically $host.UI.RawUI.SetBufferContents(...)
.
来源:https://stackoverflow.com/questions/13572705/keep-script-position-in-terminal