【问题标题】:trouble with execute command at cmd in java在java中的cmd执行命令的问题
【发布时间】:2015-07-03 18:40:06
【问题描述】:

我想重新启动我的 adsl 调制解调器,我的代码是这样的。代码运行良好,直到到达登录部分,我必须输入用户名(管理员)并按 enter 。问题是/c 不起作用(/c admin)。我怎么写管理员然后按回车?

public static void main(String[] args) throws IOException
{

    String tel = "telnet 192.168.1.1 23";
    String user = "admin";
    String pass = "admin";
    String reboot = "reboot";
    String command = "cmd /c start cmd.exe /c"+tel;
    Process child = Runtime.getRuntime().exec(command);


}

我登录部分的意思是这张图:

http://s1.postimg.org/eb74ryahb/Untitledsd.png

【问题讨论】:

    标签: java command


    【解决方案1】:
    Process child = Runtime.getRuntime().exec(command);
    Writer writer = new java.io.OutputStreamWriter(child.getOutputStream());
    writer.append("string");
    writer.flush();
    

    在此之后,您将再次读取输入以查看它是否要求输入密码或其他任何内容。

    【讨论】:

    • 它不起作用。它不会将 string 附加到 cmd 中的光标。
    猜你喜欢
    • 2015-01-10
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 2011-07-12
    • 2015-01-23
    相关资源
    最近更新 更多