Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell output column width

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.

like image 854
maxfridbe Avatar asked Jun 11 '09 00:06

maxfridbe


People also ask

How do I display output in a table Format in PowerShell?

The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display.

How do I expand a field in PowerShell?

Use the –ExpandProperty parameter from Select-Object to expand objects in Windows PowerShell.

How do I use AutoSize in PowerShell?

If you specify the AutoSize parameter when you run the Format-Table command, PowerShell calculates column widths based on the actual data displayed. This makes the columns readable. The Format-Table cmdlet might still truncate data, but it only truncates at the end of the screen.

What is Format wide in PowerShell?

The Format-Wide cmdlet formats objects as a wide table that displays only one property of each object. You can use the Property parameter to determine which property is displayed.


1 Answers

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) 
like image 51
Emperor XLII Avatar answered Sep 29 '22 18:09

Emperor XLII