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?
The code is:
git push origin master
Write-Host "lastExitCode: $lastExitCode Last command was successful: $?"
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
And this in the console:
Everything up-to-date
lastExitCode: 0 Last command was successful: True
You can see that the success status is not the same also.
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:
and compare it to the ISE:
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.