Powershell:更新当前输出线 [英] Powershell: Update current output line

查看:77
本文介绍了Powershell:更新当前输出线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在powershell中更新命令输出的当前行?

is there a way to update the current line of the command output in powershell?

我知道如何写到同一行:

i know how to write to the same line:

Write-Host "hello " -NoNewLine

Write-Host "world!" -NoNewLine

但是有没有办法完成替换当前行?像这样:

but is there a way to complete replace the current line? something like:

Write-Host "hello "
Write-Host "world!" -ReplaceLine

提前谢谢!

解决方案:

Write-Host "hello " -NoNewLine
Write-Host "`rworld!"

推荐答案

使用回车键返回到行首:`r

Use carriage return to return to the start of the line: `r

查看此内容: http://ss64.com/ps/syntax-esc.html

回车的定义: http://en.wikipedia.org/wiki/回车

如果要清除一行,则需要清除一行空格.否则,您可以覆盖内容.

If you want to clear a line, that and a load of spaces. Otherwise you can overwrite stuff.

我不能在这里真正写一个示例,因为它是SO的代码字符,但请将其放在"world"字符串的开头,它应该可以工作.

I can't really write up an example here as it's SO's code character, but put it at the start of the "world" string and it should work.

希望这会有所帮助!

这篇关于Powershell:更新当前输出线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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