最後完成時顯示為:
若要在 C# 執行上述 git 指令,通常使用 System.Diagnostics.Process 來呼叫執行,其程式碼如下:
static void Main(string[] args)執行結果為:
{
Process myProcess = new Process();
ProcessStartInfo info = new ProcessStartInfo("git.exe", "clone git://github.com/joyent/node");
info.CreateNoWindow = true;
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
info.WorkingDirectory = "";
myProcess.StartInfo = info;
myProcess.OutputDataReceived += new DataReceivedEventHandler(myProcess_OutputDataReceived);
myProcess.Start();
myProcess.BeginOutputReadLine();
myProcess.WaitForExit();
myProcess.Close();
}
static void myProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
if (!String.IsNullOrEmpty(e.Data))
{
Console.WriteLine("captured line> "+e.Data);
}
}
cmd.exe /C “git.exe clone git://github.com/joyent/node –progress 2>&1”程式碼修改為:
ProcessStartInfo info = new ProcessStartInfo("cmd.exe", "/C " + "" + "git.exe clone git://github.com/joyent/node --progress 2>&1" + "");執行結果為:
0 意見 :
張貼留言