Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Shell - IO redirection
    primarykey
    data
    text
    <p>I am writing a replacement Windows shell in C#, and the feature I am currently implementing is having all IO inside the same shell window - ie, not opening cmd.exe in another window.</p> <p>Right now, I have a partial solution to output. This is my code (where p is the running Process):</p> <pre><code>while ( !p.HasExited ) { /* ... - irrelevant */ if ( redirect ) { try { p.BeginOutputReadLine(); } catch { } } } </code></pre> <p>The process is set up with all the correct properties, such as<code>UseShellExecute</code> = <code>False</code>, <code>RedirectStandard{Input, Output, Error}</code> = <code>True</code>, and the event handlers are set up correctly, but it's inconsistent.</p> <p>I have tried taking out the try/catch (which I know is extremely bad practice), and using a busy bool, which is set to false when the handler runs, but for some reason, I still get an InvalidOperationException on p.BeginOutputReadLine() - stating that there is already an async operation running.</p> <p>Any help would be appreciated, even if it requires a completely different solution to the one above, rather than just fixing it.</p> <p>Thanks.</p> <p><strong>EDIT</strong>: Here is the code which starts the process:</p> <pre><code>if (redirect) { p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.UseShellExecute = false; p.OutputDataReceived += new DataReceivedEventHandler(redirectHandler_StdOut); p.ErrorDataReceived += new DataReceivedEventHandler(redirectHandler_StdErr); } p.Start(); </code></pre> <p>Also, I've realised that I'm not explaining what I mean by inconsistent. As they say, a picture is worth <code>2^3</code> words:</p> <p><img src="https://lucjon.fogbugz.com/default.asp?pg=pgDownload&amp;pgType=pgFile&amp;ixBugEvent=36&amp;ixAttachment=2&amp;sTicket=&amp;sFileName=lshell%20-%20rdrio.bmp" alt="screenshot"></p>
    singulars
    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