powershell - Powershell输出列宽度

标签 powershell console

如果我有一个可执行的out.exe,并且它的stdout被重定向到文件,
即:
out.exe > $file
现在,如果我这样做,它只会输出:

<-----------------------------> 
80 columns per line to the file

有没有办法使标准输出的控制台列数更宽?
out.exe以某种方式弄乱了列吗?
就我而言,我正在使用fxcopcmd.exe

最佳答案

不久前,我遇到了类似的问题。这是我修复它的方法:

# Update output buffer size to prevent clipping in Visual Studio output window.
if( $Host -and $Host.UI -and $Host.UI.RawUI ) {
  $rawUI = $Host.UI.RawUI
  $oldSize = $rawUI.BufferSize
  $typeName = $oldSize.GetType( ).FullName
  $newSize = New-Object $typeName (500, $oldSize.Height)
  $rawUI.BufferSize = $newSize
}

它只是在主机的RawUI输出缓冲区上设置了一个新的500个字符的宽度(尽管,由于我们在多个环境中运行构建,并且我们不希望脚本失败,因为它不能使输出变大一点,因此代码是防御性的)。

如果您在始终设置RawUI的环境中运行(大多数情况下会这样做),则可以大大简化代码:
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)

关于powershell - Powershell输出列宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/978777/

相关文章:

powershell - 即使分配了新值,变量也会保留先前的值

google-chrome - Chrome浏览器中的LargeCommandLine Firebug控制台

c - fopen 一切 - 这可能吗?

android - console.log 在 Android 2.1 模拟器中不工作

node.js - 当我使用 throw 语句时,有什么方法可以改变错误消息的颜色吗?

iis - 如何使用 Powershell 操作远程服务器上的 IIS 应用程序池列表?

regex - Powershell-替换给出奇怪的行为

powershell - 多个参数集和PowerShell

powershell - 如何在Powershell中的文件的每一行上打印/附加行索引号

c# - 更改控制台窗口的大小会引发 ArgumentOutOfRangeException