powershell - PowerShell 默认使用 Write-Host 还是 Write-Output
问题描述
当我"my text"
自己在一行上输入时,文本会输出到控制台,但默认情况下是使用Write-Host
还是Write-Output
默认(我怎么能看到 - 我的意思是,我尝试使用| Get-Member
来获得线索但不确定)?
我问的原因是我知道 Write-Host 在附近有管道命令的脚本中破坏顺序输出的已知问题。
解决方案
所以,我做了一个小测试来解决这个问题。Out-Host 和 Write-Host,无论如何都不能重定向到任何流。这就是它们的工作方式,它们只是写入默认调用流。
使用这个逻辑,
"string1" | Out-host *>$null
将输出作为“string1”,因为它不能被重定向。但,
"string1" *>$null
将不显示任何输出,因此证明,写入任何文本与将其传递给 Write-Output cmdlet 相同:
# All are same
"string"
"string" | Write-Output
Write-Output "string"
推荐阅读
- c# - 执行字符串检查
- angular - TypeError:无法读取未定义的属性“authState”
- node.js - 使用 MongoDB 的 NodeJS 嵌套组聚合
- qt - 在 QML 中使用 Brython
- python - 循环输入直到满足参数或用户输入
- c# - Json.NET TypeNameHandling 和 TypeNameAssemblyFormatHandling
- java - 创建包含收件人、主题、正文和附件的电子邮件
- c# - Unity 中的 C#:在不阻塞主线程的情况下调用 Promise 风格的异步方法
- ubuntu - Anki 上的 LATEX 无法正常显示;Ubuntu 18.10
- c# - 如果 2 个图像匹配,如何使 2 个图片框不可见