Powershell output column width

2019-01-08 17:32发布

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

out.exe > $file

Right now if I do this it only outputs:

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

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.

4条回答
甜甜的少女心
2楼-- · 2019-01-08 17:44

Both the out-file and out-string cmdlets have a width parameter:

out.exe | out-file -width 132 -filePath $file
查看更多
爷、活的狠高调
3楼-- · 2019-01-08 17:46

If you're talking about Windows PowerShell - just open "properties > Layout" increase buffer size + window size

enter image description here

查看更多
Anthone
4楼-- · 2019-01-08 17:48

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
}

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).

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)
查看更多
Lonely孤独者°
5楼-- · 2019-01-08 18:11

In my powershell script I set the first line to not do carriage returns the second line I manually did a return.

(within a loop)

Write-Host -nonewline "$var1;$var2"

Write-Host "`r"

That overrode the issue with having my line wrapped but still doing a return after each individual record.

查看更多
登录 后发表回答