请问如何调用windows自带的telnet程序,并获得其输入输出的控制
如题
------解决方案--------------------用 Process起动起来以后,用StandardInput和StandardOutput来控制
public class ExternalApplicationInvoker
{
public static int Invoke (string fullfilename, string arguments, int timeout)
{
//throw new Exception(fullfilename + ": " + arguments + ": " + timeout.ToString());
Process process = new Process();
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = arguments;
process.StartInfo.FileName = fullfilename;
process.Start();
if (process.WaitForExit(timeout))
{
return process.ExitCode;
}
else
{
process.Kill();
return 1;
}
}
public static int Invoke (string fullfilename, string arguments, int timeout,string workfolder)
{
Process process = new Process();
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = arguments;
process.StartInfo.FileName = fullfilename;
process.StartInfo.WorkingDirectory = workfolder;
process.Start();
Debug.WriteLine(process.StandardOutput.ReadToEnd());
if (process.WaitForExit(timeout))
{
Debug.WriteLine( "Output: " + process.StandardOutput.ReadToEnd());
return process.ExitCode;
}
else
{
process.Kill();
return 1;
}
}
}