我正在编写一个 C# 控制台应用程序差异工具包装器(winmerge 包装器)。
它将从 gitk TCL 逻辑中调用。 Source Code of gitk external diff tool call
我面临的问题是我无法将错误输出(或任何输出)发送到我的应用程序控制台,因为它没有出现。(我的假设是因为在 TCL 中使用“r”参数调用该进程 -声明它是只读的,但可能完全错误。) 我也无法从控制台读取。
在这个包装器中,我从文件中读取配置设置,并在解析错误时通知最终用户。
暂时出现错误:
string command = "PowerShell -Command \"Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Errors reading config.json. Check wrapperErrorLogs.txt in your git folder for detailed information.')\"";
Process psh = new Process();
psh.StartInfo.FileName = "powershell.exe";
psh.StartInfo.RedirectStandardInput = true;
psh.StartInfo.RedirectStandardOutput = true;
psh.StartInfo.CreateNoWindow = true;
psh.StartInfo.UseShellExecute = false;
psh.Start();
psh.StandardInput.WriteLine(command);
psh.StandardInput.Flush();
psh.StandardInput.Close();
psh.WaitForExit();
Console.WriteLine(psh.StandardOutput.ReadToEnd());
在这种“解决方法”中,我创建了一个带有错误的“弹出窗口”。我更喜欢标准的控制台输出,按下按键即可关闭。