为什么我的powershell一直显示不相关的错误?

问题描述 投票:0回答:1

当我使用 Powershell 时,我的命令无法识别,它总是显示这些额外的 2 个 CommandNotFoundException(CategoryInfo 和 FullQualifiedErrorId)。它并没有阻止任何东西,但只是烦人。有人知道他们为什么会出现吗?我怎样才能阻止它每次都出现? 谢谢!

PS C:\Users\jeroe> thisIsATest
thisIsATest : The term 'thisIsATest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ thisIsATest
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (thisIsATest:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我对使用命令行还很陌生,但每次输入错误的命令时,都会抛出并显示一些额外的异常。

windows powershell command-line
1个回答
0
投票
  • 您看到的是多行表示单个错误,使用

    'NormalView'首选项变量
    $ErrorView
    设置。

  • Windows PowerShell 中,这是 default 设置,获得 单行 表示的唯一方法是选择

    'Concise'
    设置;然而不幸的是,这种表示通常不能提供足够的信息来识别错误;例如:

    $ErrorView = 'CategoryView'; 1 / 0
    

    产量:

    NotSpecified: (:) [], RuntimeException
    
  • 幸运的是,PowerShell(核心)7现在默认为new(通常)单行设置,

    'Concise'
    ,通常确实提供足够的信息:

    # Note: 'Concise' is the default in PowerShell 7
    1 / 0
    

    产量:

    # In PowerShell 7
    RuntimeException: Attempted to divide by zero.
    
    • 此外,PowerShell 7 有一个
      'DetailedView'
      设置(在撰写本文时尚未记录),它提供了比
      'NormalView'
      更多的详细信息,并使用与仅限 PowerShell 7 的
      Get-Error
      cmdlet 相同的显示格式;您可以使用后者来检查错误。

© www.soinside.com 2019 - 2024. All rights reserved.