[英]System.Management.Automation.Powershell.Invoke() claims HadErrors when there were none
I'm having an issue with the following code where it works fine on computers who have Powershell version 1-4 but when ran on a computer with Powershell V5, the test, "posh.HadErrors" is returning true. 我在使用以下代码时遇到问题,该代码在具有Powershell 1-4版本的计算机上可以正常工作,但是在具有Powershell V5的计算机上运行时,测试“ posh.HadErrors”返回true。 I tried this on a clean vagrant install so it's not a profile or env var issue.
我在干净的无用安装上尝试了此操作,因此它不是配置文件或环境变量问题。 Any git command I try running, powershell claims to have errors when running on a computer with v5 installed.
我尝试运行的任何git命令,在安装了v5的计算机上运行时,powershell都声称有错误。 I'm not even sure how to debug this issue.
我什至不知道如何调试此问题。
using (var posh = PowerShell.Create())
{
string resultString = "";
posh.AddScript("git checkout master");
var results = posh.Invoke();
foreach (var result in results)
{
if (result == null) { continue; }
if (posh.HadErrors)
{
// This is getting hit when it shouldn't when running Powershell V5
_console.LogError(result.ToString());
}
else
{
resultString += result + "\r\n";
_console.LogDebug(result.ToString());
}
}
foreach (var error in posh.Streams.Error)
{
_console.LogError(error.ToString());
}
return Tuple.Create(!posh.HadErrors, resultString);
}
git outputs to stderr even when there's no error. 即使没有错误,git也会输出到stderr。
Eg if it looks like this: 例如,如果看起来像这样:
> git checkout master
Already on 'master'
Your branch is up-to-date with 'origin/master'.
That first line is error output. 第一行是错误输出。
If it looks like this: 如果看起来像这样:
> git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
That first line is still error output. 第一行仍然是错误输出。
You can verify it by running the command like this: 您可以通过运行以下命令来验证它:
git checkout master 1>output.log 2>error.log
如果HadErroes等于true,请检查PowerShellInstance.InvocationStateInfo.Reason以查看异常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.