【发布时间】:2018-01-17 11:52:38
【问题描述】:
您好,我正在尝试使用 power shell 和 c# 作为管理工具创建某种混合,因此 powershell 中的简单脚本可以检查 repo 状态
$git_status = git status
Write-Output $git_status
现在使用管道并运行
using (Runspace runspace = RunspaceFactory.CreateRunspace())
{
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(powershellScript);
pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
StringBuilder output = new StringBuilder();
foreach (PSObject obj in results)
{
output.AppendLine(obj.ToString());
}
return output.ToString();
}
但是我得到空结果,当我在 IDE power shell 中运行脚本时,结果如下所示:
写主机“$git_status” 在分支 master 你的分支是最新的'origin/master'。要提交的更改: (使用“git reset HEAD ...”取消暂存)修改:DeviceDatabase/Platforms.xml
我能做些什么来让这个响应返回到 c# 过程?
【问题讨论】:
-
据我了解,powershell 和 git 并不能很好地配合使用。 PS 操作记录,git 输出原始字节流。既然你无论如何都要写代码,你可能最好只阅读 gits 输出,然后用 C# 处理它
标签: c# git powershell