Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从字符串中获取命令(密码),并将其设置为Java(JSCH)中Unix服务器的InputStream_Java_Linux_Shell_Unix_Jsch - Fatal编程技术网

从字符串中获取命令(密码),并将其设置为Java(JSCH)中Unix服务器的InputStream

从字符串中获取命令(密码),并将其设置为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

几乎和主题类似,但在这里我并不是一个超级用户——stdin

所以我找到了另一种方法,在后台打开一个“shell”,通过
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

只是一个更新,您清楚解释了吗?