0

コンソールに書き込む.exeを実行するbatファイルですが、実行中ではなく、実行可能ファイルが終了した後に結果が一度に返されます。

デスクトップから .bat を手動で実行しましたが、これは正常に動作し、行ごとに結果を返しますが、C# アプリでは行ごとに運がありません。何か案は?

var startInfo = new ProcessStartInfo();

    startInfo.FileName = @"C:\Desktop\TEST\test.bat"; /
    startInfo.UseShellExecute = false;
    startInfo.CreateNoWindow = false;
    startInfo.RedirectStandardOutput = true;
    startInfo.WorkingDirectory = @"C:\Desktop\TEST\";
    startInfo.RedirectStandardError = true;

using (Process Process = Process.Start(startInfo))
{
  using (var reader = (Process.StandardOutput))
  {
  Console.WriteLine(reader.ReadToEnd());
  }
}
4

1 に答える 1

1

次の記事では、表示されている動作について説明する必要があります。ReadToEnd は同期操作であり、BeginOutputReadLine は非同期操作であるため、ニーズにより適しているはずです。

于 2013-07-29T15:23:19.133 に答える