Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell CLI on Unix doesn't use the current terminal's window width when stringifying formatted output for outside callers with captured / redirected stdout output #20110

Open
5 tasks done
mklement0 opened this issue Aug 12, 2023 · 2 comments
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@mklement0
Copy link
Contributor

mklement0 commented Aug 12, 2023

Prerequisites

Steps to reproduce

Scenario:

  • A PowerShell CLI call is made that results in formatted output (such as implicit Format-Table) which is returned in stringified form to the CLI caller.

  • Generally, if the call is made from a terminal, it is that terminal's window width that determines the max. length of the formatted lines.

    • On Windows, this is always true.
    • On Unix, if the stdout target isn't a terminal, a fixed width of 80 characters is unexpectedly applied.
      • Notably, this also applies when the caller redirects the CLI output to a file.
# On Unix, the output lines are unexpectedly limited to 80 characters, irrespective of terminal width.
pwsh -NoProfile -c "[pscustomobject] @{ Foo = 'x' * 500 }" | Write-Output

On a related note, for the fundamental question as to whether the terminal width should be a factor in Out-String and Out-File / > calls, see:

(In the case of the implicit stringification (implicit Out-String -Stream) that happens via the CLI, the decision as to whether to apply a limit or not could again be based on whether stdout is redirected or not).


Expected behavior

The formatted output should fill the entire terminal width (assuming a width greater than 80 characters).
This is true on Windows, but not on Unix-like platforms.

Actual behavior

The output is cut off at 79 characters.

Error details

No response

Environment data

PowerShell 7.4.0-preview.4 on macOS 13.4.1 and Ubuntu 20.03 (via WSL)

Visuals

No response

@mklement0 mklement0 added the Needs-Triage The issue is new and needs to be triaged by a work group. label Aug 12, 2023
@mklement0 mklement0 changed the title PowerShell CLI on Unix doesn't use the current terminal's window width when stringifying formatted output for outside callers with redirections PowerShell CLI on Unix doesn't use the current terminal's window width when stringifying formatted output for outside callers with captured / redirected stdout output Aug 12, 2023
@237dmitry
Copy link

237dmitry commented Aug 12, 2023

Interesting, if run this from the current session then output respects terminal window width. But from another session pwsh -c .... ignores it and outputs (default?) 80-columns. Output difference between current and other session:

pwsh -NoProfile -c "[pscustomobject] @{ Foo = 'x' * 500 }" | Write-Output  # 80
pwsh -NoProfile -c "[pscustomobject] @{ Foo = 'x' * 500 } | Write-Output"  # full width

@nwsparks
Copy link

nwsparks commented Apr 23, 2024

thanks for posting this. I've spent a mountain of time trying to figure out how to resolve Jenkins truncating powershell output at 80 characters and this explains it. hopefully it can get some more attention in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

3 participants