如何在expectj中处理密码提示

时间:2012-11-08 14:07:36

标签: jsch expectj

我想通过expectj发送“su root”命令(事实上它是jsch)。它请求密码。有没有办法在expectj中处理它?<​​/ p>

1 个答案:

答案 0 :(得分:1)

    ExpectJ ex = new ExpectJ(30);
    Spawn spawn = ex.spawn(new SshSpawn("192.168.56.101", 22, "alice", "alicepassword"));
    spawn.send("su root\n");
    spawn.expect("assword");
    spawn.send("yourpassword\n");
    try{
        spawn.interact();   
    }catch(NullPointerException npe){   
        //ignore, seems like some strange expectj bug
    }