将">"添加到Process.Start实例

Tom*_*Tom 1 .net c# windows

我怎么能告诉程序"test.exe"(这是一个控制台应用程序)将其结果输出到文件.

例如,通常程序可以通过在提示符下执行test.exe> output.txt来输出数据.

怎么可以在这个声明中做到这一点?

Process.Start("test.exe", "\"" + exename + "\"").WaitForExit();
Run Code Online (Sandbox Code Playgroud)

Chr*_*isF 7

StandardOutput在MSDN页面中使用此示例中的属性:

// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Run Code Online (Sandbox Code Playgroud)

如您所见,您需要设置's 的RedirectStandardOutput属性.ProcessStartInfo