Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command);
channel.setXForwarding(true);
channel.connect();
InputStream in = channel.getInputStream();
byte[] tmp = new byte[7196274];
while (true) {
while (in.available() > 0) {
System.out.println("in try");
int i = in.read(tmp, 0, 7196274);
System.out.println("in try i val" + i);
if (i < 0)
break;
String strResult = new String(tmp, 0, i);
System.out.println(strResult);
}
if (channel.isClosed()) {
in.close();
break;
}
此代码仅为小文件提供正确的输出。我想直接将输出读入文件而不使用字节?
答案 0 :(得分:0)
你必须管道结果。例如: ps -ef&gt;文件名