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

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

问题描述

如果我有一个exe:out.exe和它的stdout重定向到一个文件
ie:

If i have an exe: out.exe and its stdout is redirected to a file ie:

out.exe > $ file

现在如果我这样做只输出
<----------- ------------------>
到文件

Right now if i do this it only outputs <-----------------------------> 80 columns per line to the file

有办法使控制台列计数的标准输出更宽?
是out.exe,它会以某种方式混乱列。
在我的case im使用fxcompcmd.exe

is there a way to make the standard output to be wider in console column count? is it the out.exe thats somehow messing with the columns.. in my case im using fxcompcmd.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天全站免登陆