为什么 Powershell ISE 会显示 Powershell 控制台未显示的错误? [英] Why is Powershell ISE showing errors that Powershell console does not show?

查看:74
本文介绍了为什么 Powershell ISE 会显示 Powershell 控制台未显示的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Powershell ISE(手动加载脚本并按 F5)和 Powershell 控制台(执行脚本文件)中运行完全相同的 script.ps1 文件.它们都可以工作,但 ISE 显示控制台没有的错误.为什么?

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). They both work but ISE shows errors that the console does not. Why?

代码是:

git push origin master
Write-Host "lastExitCode: $lastExitCode Last command was successful: $?"

此代码在 ISE 中输出此错误:

This code output this error in the ISE:

git.cmd : Initializing to normal mode
At E:\script.ps1:28 char:4
+ git <<<<  push origin master
    + CategoryInfo          : NotSpecified: (Initializing to normal mode:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Initializing to normal mode

Everything up-to-date

lastExitCode: 0 Last command was successful: False

在控制台中:

Everything up-to-date
lastExitCode: 0 Last command was successful: True

你可以看到成功状态也不一样.

You can see that the success status is not the same also.

推荐答案

我不知道为什么它们的输出不同,但是我们从 git push 看到的消息是通过 stderr 来的.这意味着它们显示错误,尽管 ISE 使它们更响亮,并将其转换为错误对象.

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.

考虑来自 PowerShell 提示符的输出:

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>

并将其与 ISE 进行比较:

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>

除了正在显示的错误对象的额外输出之外,输出是相同的.ISE 已将 stderr 字符串转换为 NativeCommandError 对象,如果您看过去,它甚至会显示错误消息.

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.

这篇关于为什么 Powershell ISE 会显示 Powershell 控制台未显示的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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