Powershell 输出列宽 [英] Powershell output column width

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

问题描述

如果我有一个可执行文件 out.exe 并且它的 stdout 被重定向到一个文件,即:

If I have an executable out.exe and it's stdout is redirected to a file, i.e.:

out.exe >$文件

现在如果我这样做,它只会输出:

Right now if I do this it only outputs:

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

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

Is there a way to make the standard output to be wider in console column count? Is it the out.exe that's somehow messing with the columns? In my case I'm using fxcopcmd.exe.

推荐答案

不久前我遇到了类似的问题.这是我为修复它所做的:

I encountered a similar problem a while back. Here's what I did to fix it:

# 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 个字符的宽度(尽管如此,因为我们在多个环境中运行我们的构建,我们不希望脚本仅仅因为它不能使输出更大一点而失败,代码相当防御).

It simply sets a new width of 500 characters on the host's RawUI output buffer (though, since we run our build in several environments, and we did not want the script to fail just because it could not make the output a bit larger, the code is rather defensive).

如果您在始终设置 RawUI(大多数都设置)的环境中运行,则代码可以大大简化:

If you run in an environment that always sets RawUI (and most do), the code can be greatly simplified:

$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)

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

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