Redirect the output (stdout, stderr) of a child process to the Output window in Visual Studio

前端 未结 4 1933
孤独总比滥情好
孤独总比滥情好 2020-12-06 01:37

At the moment I am starting a batch file from my C# program with:

System.Diagnostics.Process.Start(@\"DoSomeStuff.bat\");

What I would like

4条回答
  •  眼角桃花
    2020-12-06 01:54

    process.StartInfo.CreateNoWindow = true;
    process.StartInfo.UseShellExecute = false;
    process.StartInfo.RedirectStandardOutput = true;
    process.OutputDataReceived += (sender, args) => Console.WriteLine(args.Data);
    process.Start();
    process.BeginOutputReadLine();
    
    process.WaitForExit();
    

    Same idea for Error, just replace Output in those method/property names.

提交回复
热议问题