0
class Program
{
    public static void ExecuteCommand(string Command)
    {
        ProcessStartInfo ProcessInfo;
        Process Process;

        ProcessInfo = new ProcessStartInfo("cmd.exe", "/C " + Command);
        ProcessInfo.CreateNoWindow = false;
        ProcessInfo.UseShellExecute = false;
        Process = Process.Start(ProcessInfo);
        Process.WaitForExit();

        Process.Close();


    }



    static void Main()
    {

        ExecuteCommand("telnet 169.254.0.1");


    }
}

它运行 cmd 并通过 telnet 连接到特定设备。接下来,一旦连接,它会提示输入我也想发送的登录名和密码,然后是一些特定的命令。我应该怎么办?

非常感谢!

4

1 回答 1

3

只需写入 StandardInput 流。

Process process = Process.Start("cmd");

if (process != null)
{
   process.StandardInput.WriteLine("dir");
   process.StandardInput.WriteLine("ping");
   process.StandardInput.WriteLine("something");
}
于 2012-05-14T16:50:56.647 回答