Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirectStandardIn Stops Output
    primarykey
    data
    text
    <p>I have a GUI that wraps a console application to improve user experience. I'm using the Process class to spin off the console executable. I want the console window to come up, and I will manually write abbreviated output to it. Then, once the executable is finished, the console window will close and control passes back to the GUI.</p> <p>However, it is an interactive program, requiring me to redirect both StandardIn and StandardOut. The problem is that the very act of redirecting the input stops all output from coming to the console.</p> <p>I've included all the output code as I had it, but commented out. As it is, a console window will open and the prompts will appear, waiting for user input. If I uncomment RedirectStandardIn, the window appears, but simply remains blank. Am I misunderstanding the role of Process.StandardInput?</p> <pre><code>class HandleExecutable { ... public void callExecutable(string executable, string args, string inputStr) { string commandLine = executable; ProcessStartInfo psi = new ProcessStartInfo(commandLine); psi.UseShellExecute = false; psi.LoadUserProfile = false; //psi.RedirectStandardOutput = true; //psi.RedirectStandardError = true; /* UNCOMMENT BELOW WILL CAUSE NO OUTPUT TO BE PUT TO THE CONSOLE */ //psi.RedirectStandardInput = true; psi.WindowStyle = ProcessWindowStyle.Minimized; psi.Arguments = args; Process p = new Process(); p.StartInfo = psi; try { p.Start(); //p.StandardInput.WriteLine(inputStr); //p.BeginOutputReadLine(); //p.BeginErrorReadLine(); if (outputHandler != null) p.OutputDataReceived += outputHandler; if (errorHandler != null) p.ErrorDataReceived += errorHandler; p.WaitForExit(); p.Close(); p.Dispose(); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } } </code></pre>
    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.
    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