Hello,
I need to pass a simple string to a command window (running telnet), from a c# winforms app... is there a simple way to do this?
I tried the following, but it's all or nothing when redirecting standardinput--
the winforms app doesnt have to start the cmd window... the cmd window could already be running also-- I thought maybe that would be how to communicate with it--
there's 1 or 2 ?'s similar to this on so, but no one really nailed it...
p/invoking is ok also...
please help!
Process p = new Process();
StreamWriter sw;
//StreamReader sr;
//StreamReader err;
ProcessStartInfo psi = new ProcessStartInfo(@"cmd.exe", @"/C telnet 192.168.0.10");
private void start
{
psi.WindowStyle = ProcessWindowStyle.Normal;
psi.RedirectStandardOutput = false;
psi.RedirectStandardInput = true;
psi.UseShellExecute = false;
psi.CreateNoWindow = false;
p.StartInfo = psi;
p.Start();
}
private void write_to_cmd(object sender, EventArgs e)
{
psi.RedirectStandardInput = true;
sw = p.StandardInput;
////sr = p.StandardOutput;
////err = p.StandardError;
//sw.AutoFlush = true;
if (tbComm.Text != "")
sw.WriteLine(tbComm.Text);
////sw.Close();
////textBox1.Text = sr.ReadToEnd();
////textBox1.Text += err.ReadToEnd();
//p.WaitForExit();
}
}
}