question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why does console size affects powershell redirection

See original GitHub issue

Start with a narrow (50 characters) console window and run:

PS C:\temp> ps >ps.txt
PS C:\temp> (gc .\ps.txt | %{ $_.length } | measure-object -max).maximum
49
PS C:\temp>

Then make your console window full screen and run it again:

PS C:\temp> ps >ps.txt
PS C:\temp> (gc .\ps.txt | %{ $_.length } | measure-object -max).maximum
157
PS C:\temp>

Why does the console size affect output written to (redirected to) a file?

Is there a way to not see this behavior? I’d like my scripts to generate the same file data regardless of the size of the console they happen to be invoked in.

In Linux/bash, you can only query the window dimensions thru a tty handle, and when you redirect an operation to a file handle, that query fails, so all console/window processing (even pagers) get disabled… But with powershell, it seems file redirection still leaves the underlying operation inherently knowing (and using!) the console handle (that is not even involved in the write!).

Thanks for any explanation!

PS You can see the same behavior with write-information “…” 6>file, but not with write-output “…” >file – I am not sure why…

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vexx32commented, May 27, 2021

Opened #15474 to track the future enhancement. 🙂

1reaction
vexx32commented, May 27, 2021

Wow, that is totally nice thank you – this makes everything good for me, without resizing my window!!!

$PSDefaultParameterValues['out-file:width'] = 1000

Thank you again!

PS is there a list of default parameter values documented anywhere? How did you find this?

Basically it can be used to set any cmdlet/function’s default parameter values for the session. The syntax is $PSDefaultParameterValues['Cmdlet-Name:ParameterName'] = $value – and note that you can use wildcards for cmdlet or parameter names, so for example you could enable -Force by default for all *Item commands (get-item, get-childitem, etc) with: $PSDefaultParameterValues['*-*Item:Force'] = $true

That it works for > is basically an implementation detail because > is calling the Out-File cmdlet implicitly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Redirection - PowerShell
Explains how to redirect output from PowerShell to text files. Long description. By default, PowerShell sends output to the PowerShell host.
Read more >
How Can I Expand the Width of the Windows PowerShell ...
Run the script and your Windows PowerShell window will instantly resize itself. (Although we should note that the effect is temporary: the ...
Read more >
Powershell output column width
It simply sets a new width of 500 characters on the host's RawUI output buffer (though, since we run our build in several...
Read more >
Redirecting output - PowerShell
All the Out cmdlets render output as text, using the formatting in effect for the console window, including line length limits. Discarding ...
Read more >
Redirect output of running a file to both the console and ...
Its pretty much all said in the title but suppose I have a file hello.ps1 its only line of code is. write-host "hello...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found