4,358
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
Process p = null;
p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "/K start telnet 192.168.8.101";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
p.Start();
p.OutputDataReceived+=new DataReceivedEventHandler(p_OutputDataReceived);
SendKeys.Send("123456\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("enable\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("123456\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("configure terminal\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("interface pon 1/1\r");
System.Threading.Thread.Sleep(500);
SendKeys.Send("show legal-onu-info\r");
System.Threading.Thread.Sleep(800);
p.BeginOutputReadLine();
p.WaitForExit();
p.Close();
}
private void p_OutputDataReceived(object Sender, DataReceivedEventArgs e)
{
if (e.Data != null)
{
result = e.Data;
}
}