From d20c727d39b080f5c5956ddd81d344f623c8375a Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 14 Feb 2018 20:11:45 -0800 Subject: [PATCH] Enable $env:PAGER to work correctly if arguments are used (#6144) Correctly parse $env:PAGER with args like 'less -w'. --- .../engine/InitialSessionState.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 51f25e23e6..68a37b8c3a 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4756,7 +4756,8 @@ $OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or # Respect PAGER, use more on Windows, and use less on Linux if (Test-Path env:PAGER) { - $moreCommand = (Get-Command -CommandType Application $env:PAGER | Select-Object -First 1).Definition + $pager,$moreArgs = $env:PAGER -split '\s+' + $moreCommand = (Get-Command -CommandType Application $pager | Select-Object -First 1).Definition } elseif ($IsWindows) { $moreCommand = (Get-Command -CommandType Application more | Select-Object -First 1).Definition } else { @@ -4765,9 +4766,9 @@ if (Test-Path env:PAGER) { if($paths) { foreach ($file in $paths) { - Get-Content $file | & $moreCommand + Get-Content $file | & $moreCommand $moreArgs } -} else { $input | & $moreCommand } +} else { $input | & $moreCommand $moreArgs } "; internal const string DefaultSetDriveFunctionText = "Set-Location $MyInvocation.MyCommand.Name";