Read from standard error of child process
suggest changevar errors = new System.Text.StringBuilder(); var process = new Process { StartInfo = new ProcessStartInfo { RedirectStandardError = true, FileName = "xcopy.exe", Arguments = "\"NonExistingFile\" \"DestinationFile\"", UseShellExecute = false }, }; process.ErrorDataReceived += (s, e) => errors.AppendLine(e.Data); process.Start(); process.BeginErrorReadLine(); process.WaitForExit(); if (errors.Length > 0) // something went wrong System.Console.Error.WriteLine($"Child process error: \r\n {errors}");
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents