Note that there are some explanatory texts on larger screens.

plurals
  1. POSending input/getting output from a console application (C#/WinForms)
    primarykey
    data
    text
    <p>I have a form with 3 controls:</p> <ol> <li>A textbox for the user to enter commands to send to a console application,</li> <li>A button to confirm the commands to be sent and</li> <li>A read-only textbox to display the output from the application.</li> </ol> <p>What I want is for the user to enter commands in the first textbox, press the button to enter and receive feedback via the second textbox.</p> <p>I know how to use <code>ProcessStartInfo.RedirectStandardOutput</code> but, however, the app hangs when I use <code>StandardOutput.ReadToEnd()</code>. </p> <p>I had a look at the asynchronous <code>Process.BeginOutputReadLine()</code> but, even though my app does not hang, somehow I get no response in the textbox, it does absolutely nothing.</p> <p>Here's my code:</p> <pre><code>public partial class MainForm : Form { private void MainForm_Load(object sender, EventArgs e) { InitializeInterpreter(); } private void InitializeInterpreter() { InterProc.StartInfo.UseShellExecute = false; InterProc.StartInfo.FileName = "app.exe"; InterProc.StartInfo.RedirectStandardInput = true; InterProc.StartInfo.RedirectStandardOutput = true; InterProc.StartInfo.RedirectStandardError = true; InterProc.StartInfo.CreateNoWindow = true; InterProc.OutputDataReceived += new DataReceivedEventHandler(InterProcOutputHandler); InterProc.Start(); } private static void InterProcOutputHandler(object sendingProcess, DataReceivedEventArgs outLine) { if (!String.IsNullOrEmpty(outLine.Data)) { OutputTextBox.Append(Environment.NewLine + outLine.Data); } } private void Enterbutton_Click(object sender, EventArgs e) { InterProc.StandardInput.Write(CommandtextBox.Text); InterProc.BeginOutputReadLine(); } } </code></pre> <p>Is there any way I can have this run smoothly? Thanks.</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