我在Powershell ISE中手动加载脚本并按F5键,以及在Powershell控制台中执行脚本文件,运行的是完全相同的script.ps1文件。它们都能正常工作,但ISE会显示控制台没有的错误。为什么?
代码如下:
git push origin master
Write-Host "lastExitCode: $lastExitCode Last command was successful: $?"
这段代码在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
你可以看到成功的状态也不一样。
$null
,你应该能够避免消息中的差异,只需检查LastExitCode
来查看它的执行情况。 - Ryan Hiebert