我想從c#運行git命令。下面是我編寫的代碼,它確實執行了git命令,但我無法捕獲返回值。當我從命令行手動運行它時,這是我得到的輸出。使用c獲得git命令行返回值#
當我從程序來看,我唯一得到的就是信息沒有捕捉
Cloning into 'testrep'...
休息,但該命令執行成功。
class Program
{
static void Main(string[] args)
{
ProcessStartInfo startInfo = new ProcessStartInfo("git.exe");
startInfo.UseShellExecute = false;
startInfo.WorkingDirectory = @"D:\testrep";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.Arguments = "clone http://tk1:[email protected]/testrep.git";
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
List<string> output = new List<string>();
string lineVal = process.StandardOutput.ReadLine();
while (lineVal != null)
{
output.Add(lineVal);
lineVal = process.StandardOutput.ReadLine();
}
int val = output.Count();
process.WaitForExit();
}
}