"more.com"返回“内存不足". [英] `more.com` returns "Not enough memory."

查看:59
本文介绍了"more.com"返回“内存不足".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

环境详细信息:

  • x64 Win7 SP1 Enterprise
  • Windows PowerShell v5.0

在未加载任何配置文件的情况下,我的本地会话正在返回

Without any profiles loaded, my local powershell sessions are returning

没有足够的内存.

Not enough memory.

当我尝试执行 help man 时.无论我使用的是本机 powershell.exe 还是.

when I try to execute help or man. This occurs whether I'm using the native powershell.exe or conemu.

奇怪的是,我能够执行我尝试过的任何其他别名,并且它不会添加到 $ Error 变量中,所以我不知道从哪里开始进行故障排除(我已经尝试 -ErrorAction Stop $ ErrorActionPreference ='Stop').

Strangely, I am able to execute any other aliases I've tried, and it doesn't add to the $Error variable, so I have no idea where to start troubleshooting (I've tried -ErrorAction Stop and $ErrorActionPreference = 'Stop').

作为脚注,我没有任何提升的特权.

As a footnote, I don't have any elevated privileges.

经过一番探索,我发现 man 实际上是 help 的别名,而不是 Get-Help 的别名,但是具有以下定义的自身功能:

After some exploration, I found that man is actually an alias for help which isn't an alias for Get-Help, but a function of its own with this definition:

function help {
<#
.FORWARDHELPTARGETNAME Get-Help
.FORWARDHELPCATEGORY Cmdlet
#>
    [CmdletBinding(DefaultParameterSetName = 'AllUsersView', HelpUri = 'http://go.microsoft.com/fwlink/?LinkID=113316')]
    param(
        [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)]
        [string]
        ${Name},

        [string]
        ${Path},

        [ValidateSet('Alias', 'Cmdlet', 'Provider', 'General', 'FAQ', 'Glossary', 'HelpFile', 'ScriptCommand', 'Function', 'Filter', 'ExternalScript', 'All', 'DefaultHelp', 'Workflow', 'DscResource', 'Class', 'Configuration')]
        [string[]]
        ${Category},

        [string[]]
        ${Component},

        [string[]]
        ${Functionality},

        [string[]]
        ${Role},

        [Parameter(ParameterSetName = 'DetailedView', Mandatory = $true)]
        [switch]
        ${Detailed},

        [Parameter(ParameterSetName = 'AllUsersView')]
        [switch]
        ${Full},

        [Parameter(ParameterSetName = 'Examples', Mandatory = $true)]
        [switch]
        ${Examples},

        [Parameter(ParameterSetName = 'Parameters', Mandatory = $true)]
        [string]
        ${Parameter},

        [Parameter(ParameterSetName = 'Online', Mandatory = $true)]
        [switch]
        ${Online},

        [Parameter(ParameterSetName = 'ShowWindow', Mandatory = $true)]
        [switch]
        ${ShowWindow}
    )

    #Set the outputencoding to Console::OutputEncoding. More.com doesn't work well with Unicode.
    $outputEncoding = [System.Console]::OutputEncoding

    Get-Help @PSBoundParameters | more
}

更进一步... 更多是另一个功能:

Even further... more is another function:

function more {
    param([string[]]$paths)

    $OutputEncoding = [System.Console]::OutputEncoding

    if($paths) {
        foreach ($file in $paths) {
            Get-Content $file | more.com
        }
    }
    else {
        $input | more.com
    }
}

推荐答案

more.com 的一个看似固有的缺陷,它难以处理多字节编码(例如),而是抛出一个

A seemingly inherent flaw with more.com, it has difficulty handling multi-byte encodings (such as utf-8) and will instead throw a

没有足够的内存.

Not enough memory.

错误.

我没有足够的知识来弄清楚为什么引发该消息或如何在不同系统上复制该消息(例如,我无法在x64 Windows 10 1804 Pro上复制),但是可以通过将 [System.Console] 上的 OutputEncoding 静态成员更改为默认编码(在本例中为 CP437 我的主持人的默认设置):

I don't have enough knowledge to figure out why it throws that message or how to replicate it on different systems (for example, I could not replicate on x64 Windows 10 1804 Pro), but it can be remediated by changing the OutputEncoding static member on [System.Console] to a default encoding (in this case, CP437, which was my conhost's default):

[System.Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding(437)

或其他单字节编码,例如 CP1252 .

or other single-byte encoding, such as CP1252.

如果在的问题中观察到此错误,,则可以使用 chcp.com 进行补救(未测试是否还会更新 [Console] :: OutputEncoding ):

If this error is being observed in cmd, it can be remediated using chcp.com (untested whether this also updates [Console]::OutputEncoding):

chcp.com 437


作为一个旁注,导致我失败的代码在我的 $ PROFILE 中:

[Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.UTF8Encoding]::new()

使用同一控制台主机时,问题仍然存在,即使退出当我被留在提示.

The issues persisted while using the same console host, even after exiting powershell when I was left in a cmd prompt.

要使powershell正常工作,我必须做一个组合代码页+ OutputEncoding 更改:

for powershell to work, I had to do a combined codepage + OutputEncoding change:

[Console]::OutputEncoding = [Text.Encoding]::GetEncoding(437)
& chcp.com 437

这篇关于"more.com"返回“内存不足".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆