1
      package burak;

        import java.io.*;

public class Server {
public static void main(String[] args) {
    try {
        String[] command = new String[2];
        command[0] = "cmd";
        command[1] = "telnet";

        Process p = Runtime.getRuntime().exec(command);

        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = reader.readLine();
        while (line != null) {
            System.out.println(line);
            line = reader.readLine();
        }
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
        BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        String Error;

        while ((Error = stdError.readLine()) != null) {
        System.out.println(Error);
        }
        while ((Error = stdInput.readLine()) != null) {
        System.out.println(Error);
        }
    } catch (Exception e) {
        e.printStackTrace();
 }
}

我想打开 telnet 并发送一些命令,但我无法打开 telnet 你能告诉我有什么问题吗?我需要一些关于 telnet 连接 expcect apache.common 的示例,因为我必须在一次运行中使用多个 ip,我不知道如何在这个条件下使用 args

4

0 回答 0