Hi.
There is a better way to go about doing this. I've done this by creating a
new process and redirecting the standard input, output and error using
stream readers and writers. Then throw in a text box and write some handling
code to use the textbox for the prompt's i/o.
I think I found an exmaple of this on codeproject.com or something like that
and I got something similar to the code below from someone on there so I
don't take credit for this:
//----snip----------
private void handler() {
Process myProcess = new Process();
string output;
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.RedirectStandardOutput = true;;
myProcess.StartInfo.RedirectStandardError = true;
myProcess.Start();
StreamWriter incoming = myProcess.StandardInput;
incoming.AutoFlush = true;
StreamReader outgoing = myProcess.StandardOutput;
StreamReader error = myProcess.StandardError;
incoming.Write("dir c:\\windows\\system32\\*.com" +
System.Environment.NewLine);
incoming.Write("exit" + System.Environment.NewLine);
output = outgoing.ReadToEnd();
if( !myProcess.HasExited )
myProcess.Kill();
textBox1.Text = output;
incoming.Close();
outgoing.Close();
error.Close();
myProcess.Close();
textBox1.Select(0,0);
}
//----snip----------
When done properly, this will yield something like:
http://jinx.psyjnir.net/images/cnsl.png
Note that this code will not allow for real time interraction with the
prompt. It is up to you to find an elegant way to implement that. Anyway, I
hope this helps you out some.
Ben