从字符串中获取命令(密码),并将其设置为Java(JSCH)中Unix服务器的InputStream
几乎和主题类似,但在这里我并不是一个超级用户——stdin 所以我找到了另一种方法,在后台打开一个“shell”,通过从字符串中获取命令(密码),并将其设置为Java(JSCH)中Unix服务器的InputStream,java,linux,shell,unix,jsch,Java,Linux,Shell,Unix,Jsch,几乎和主题类似,但在这里我并不是一个超级用户——stdin 所以我找到了另一种方法,在后台打开一个“shell”,通过String通过InputStream 我编写了如下代码: String s = "cd bin\n"; byte bb[] = s.getBytes(); InputStream intt = new ByteArrayInputStream(bb); channel.setInputStream(new FilterInputStream(intt) { pub
String
通过InputStream
我编写了如下代码:
String s = "cd bin\n";
byte bb[] = s.getBytes();
InputStream intt = new ByteArrayInputStream(bb);
channel.setInputStream(new FilterInputStream(intt) {
public int read(byte[] b, int off, int len) throws IOException {
return in.read(b, off, (len > 1024 ? 1024 : len));
}
});
现在,当我只想执行一个命令,但我想给出多个命令时,这种方法非常有效,这是我面临的问题
有什么建议吗
问候,
伊山我找到了我所问问题的解决方案,不知道这是否是一个完全证明的解决方案,因为我在有限的时间内进行了测试,我尽了我所能
channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
((ChannelExec) channel).setPty(true);
在命令字符串中
String command = "(echo old_password; echo new_password; echo new_password) | passwd username";
如果不是超级用户
String command = "(echo old_password; echo new_password; echo new_password) | passwd"
就是这样;)
问候,
icr只是一个更新,您清楚解释了吗?