对于标准输出和标准错误,只有某些命令才能产生任何输出。另外,我读到在两个流上调用ReadToEnd可能会导致死锁?如果有人知道更安全的方式读取流,将不胜感激。下面是我如何运行流程并获取输出。问题在于,对于fetch,输出为空(fetching命令确实起作用,但不提供输出),但对于其他命令,如pull,则为空。
ProcessStartInfo psi= new ProcessStartInfo();
psi.CreateNoWindow = true;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.FileName = "git.exe";
psi.UseShellExecute = false;
psi.WorkingDirectory = workingDir;
psi.Arguments = "fetch -v";
Process fetchProcess = new Process();
fetchProcess.StartInfo = psi;
fetchProcess.Start();
string err = "";
string stdout = "";
//Both standard error and stdout are empty. But if argument is
// a git pull, then standard error and output are not empty.
using (StreamReader myOutput = fetchProcess.StandardOutput) {
stdout = myOutput.ReadToEnd();
}
using (StreamReader myError = fetchProcess.StandardError) {
err= myError .ReadToEnd();
}
fetchProcess.WaitForExit();
fetchProcess.Close();
是否要确保已获取获取结果?