Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Essentially your problem is unsolvable. If you block your code in a button click to wait for user input you will be freezing the UI, which will prevent anyone from being able to provide said input; this is called a deadlock.</p> <p>You can open up the shell in the button click and then append to it later on after you have input, or you can wait until you already have the input to send to the shell before opening it in the first place.</p> <p>Since you asked for some code, here's my 'hello world of a shell' example. I was actually using it to play around with WPF. There's a textbox for input, a textbox to display output, and a button to send the data in the input textbox to the shell. Realize that this is neither a production quality example, nor is it specifically written in response to your question, but it should demonstrate the overall approach to the problem.</p> <pre><code> /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { private Process cmd; private bool scrollAtBottom = false; public MainWindow() { InitializeComponent(); Closed+=new EventHandler(MainWindow_Closed); textBlock1.Text = ""; textBox1.Focus(); } private void button1_Click_1(object sender, RoutedEventArgs e) { if (cmd == null || cmd.HasExited) { cmd = new Process(); cmd.StartInfo.CreateNoWindow = false; cmd.StartInfo.FileName = "cmd.exe"; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.UseShellExecute = false; cmd.OutputDataReceived += new DataReceivedEventHandler(cmd_OutputDataReceived); cmd.Start(); cmd.BeginOutputReadLine(); } cmd.StandardInput.WriteLine(textBox1.Text); textBox1.Text = ""; } private void cmd_OutputDataReceived(object sender, DataReceivedEventArgs e) { textBlock1.Dispatcher.Invoke(new Action(() =&gt; { textBlock1.Text += e.Data + Environment.NewLine; scrollViewer1.ScrollToEnd(); })); } private void MainWindow_Closed(object sender, EventArgs e) { if (cmd != null &amp;&amp; !cmd.HasExited) { //exit nicely cmd.StandardInput.WriteLine("exit"); if (!cmd.HasExited) { //exit not nicely cmd.Kill(); } } } } </code></pre>
 

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