Why is Powershell ISE showing errors that Powershell console does not show?

前端 未结 4 2062
情书的邮戳
情书的邮戳 2021-02-19 10:32

I\'m running exactly the same script.ps1 file in a Powershell ISE (manually loading the script and pressing F5) and in a Powershell console (executing the script file).

4条回答
  •  猫巷女王i
    2021-02-19 11:07

    I don't know why they output differently, but the message that we see from git push is coming over stderr. This means that they are both showing errors, although the ISE is making them much louder, and converting it into error objects.

    Consider this output from the PowerShell prompt:

    PS> git push
    Everything up-to-date
    PS> git push 2> $null    # Redirect stderr to $null
    PS> $LastExitCode
    1
    PS>
    

    and compare it to the ISE:

    PS> git push
    git : Everything up-to-date
    At line:1 char:1
    + git push
    + ~~~~~~~~
        + CategoryInfo          : NotSpecified: (Everything up-to-date:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
    PS> git push 2> $null
    PS> $LastExitCode
    1
    PS>
    

    Except for the extra output from the error object being displayed, the output is the same. The ISE has converted the stderr string to a NativeCommandError object, and it does even display the error message if you look past the red.

提交回复
热议问题