我想啓動一個cmd文件並將輸出重定向到控制檯,但它不起作用。我必須做什麼?我已經設置了startInfo.RedirectStandardOutput = true
。如何重定向cmnd輸出
com = "Parameter";
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo =
new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = Properties.Settings.Default.pathTo+ @"\Make\copy.cmd";
startInfo.Arguments = com;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
output = process.StandardOutput;
string ln;
while ((ln = output.ReadLine()) != null)
{
Console.WriteLine(line);
}
process.WaitForExit();
可能DUP授權的http://stackoverflow.com/questions/3829749/how-to-redirect-process-output-to-system-string?rq=1和http://stackoverflow.com/questions/285760/how-to-它產生了一個進程並捕獲它的stdout-in-net?rq = 1 – Matten 2013-04-09 11:00:26