我已经创建了一个C#应用程序,以便于对mercurial存储库进行更改。我使用以下代码在c#process
中运行hg命令 static void ExecuteCMDCommand(string path, string command)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
//startInfo.CreateNoWindow = false;
startInfo.WorkingDirectory = path;
startInfo.UseShellExecute = false;
startInfo.FileName = "hg.exe";
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardError = true;
//startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = command;
Process myProcess = new Process();
try
{
myProcess.StartInfo = startInfo;
var sbOut = new StringBuilder();
var sbErr = new StringBuilder();
var sw = new Stopwatch();
sw.Start();
myProcess.Start();
TimeSpan firstRead = TimeSpan.Zero;
myProcess.OutputDataReceived += (s, e) =>
{
if (firstRead == TimeSpan.Zero)
{
firstRead = sw.Elapsed;
}
sbOut.Append(e.Data);
};
Console.WriteLine("**************" + sbOut.ToString());
myProcess.ErrorDataReceived += (s, e) => sbErr.Append(e.Data);
myProcess.BeginOutputReadLine();
myProcess.BeginErrorReadLine();
var eventsStarted = sw.Elapsed;
myProcess.WaitForExit();
var processExited = sw.Elapsed;
sw.Reset();
// string strOutput = myProcess.StandardOutput.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally {
myProcess.Close();
myProcess.Dispose();
}
}
这适用于 hg status / hg branches ,但是当我执行 hg pull 时,它无效,我只看到从 http://abc.abc.com/hg/repo < / strong>即可。 我该怎么办?