我想通过expectj发送“su root”命令(事实上它是jsch)。它请求密码。有没有办法在expectj中处理它?</ p>
答案 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
}