Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to asynchronously redirect ONLY standard error stream and not standard output stream of a process in C#, .net
    primarykey
    data
    text
    <p>I am writing an application in C# that at some point starts an application as a child process using the Process class with <strong>Asynchronous IO redirection</strong> as shown below:</p> <pre><code>private void AppLaunch_Click(object sender, RoutedEventArgs e) { Process appProcess = new Process(); appProcess.StartInfo.FileName = currAppPath; appProcess.StartInfo.Arguments = ""; //Setup Redirection appProcess.StartInfo.UseShellExecute = false; appProcess.StartInfo.ErrorDialog = false; appProcess.StartInfo.RedirectStandardError = true; appProcess.EnableRaisingEvents = true; // Attach Output Handler appProcess.ErrorDataReceived += appProc_DataReceived; appProcess.Exited += appProc_Exited; buildLogConsoleOutputTxtbox.AppendText(currAppPath + "\n"); appProcess.Start(); appProcess.BeginErrorReadLine(); } private void appProc_DataReceived(object sender, DataReceivedEventArgs e) { if (!String.IsNullOrEmpty(e.Data)) { this.appendLogText(e.Data); } } private void appProc_Exited(object sender, System.EventArgs e) { Process proc = (Process)sender; // Wait a short while to allow all console output to be processed and appended Thread.Sleep(40); this.appendLogText("\n&gt;&gt;"); proc.Close(); } private void appendLogText(string logText) { // Use a delegate if called from a different thread, // else just append the text directly if (buildLogConsoleOutputTxtbox.Dispatcher.CheckAccess()) { // Thread owns the TextBox buildLogConsoleOutputTxtbox.AppendText(logText + Environment.NewLine); } else { //Invocation Required appendLogCallBack appendLog = new appendLogCallBack(buildLogConsoleOutputTxtbox.AppendText); buildlogScrollEnd buildlogscrl = new buildlogScrollEnd(buildLogConsoleOutputTxtbox.ScrollToEnd); buildLogConsoleOutputTxtbox.Dispatcher.BeginInvoke(appendLog, new object[] { logText + Environment.NewLine }); buildLogConsoleOutputTxtbox.Dispatcher.BeginInvoke(buildlogscrl); } </code></pre> <p>The Problem with this piece of code is that while I do get the <strong>stderr</strong> redirected properly to my textbox, This redirection seems to <strong><em>hide</em></strong> the process' <strong>stdout</strong> output, which I don't want redirected! </p> <p>If I redirect stdout, I can see it redirected properly, but is it impossible to just redirect stderr and not stdout? I have looked around and googled regarding this topic but all discussions seem to be regarding redirecting stdout ... such as this : <a href="https://stackoverflow.com/questions/12566166/how-to-asynchronously-read-the-standard-output-stream-and-standard-error-stream">How to asynchronously read the standard output stream and standard error stream at once</a></p> <p>I would be grateful for any help regarding this!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload