diff --git a/src/test/java/TestSSh.java b/src/test/java/TestSSh.java index 1f607f57ef8b444ff0affff2017f48c470b1921e..76257b39e5623a2472531c4dac5d82ad216a49ae 100644 --- a/src/test/java/TestSSh.java +++ b/src/test/java/TestSSh.java @@ -11,5 +11,53 @@ import java.io.*; public class TestSSh { private static final String charset = "UTF-8"; // 设置编码格式 + public static void main(String[] args) throws Exception { + Session session = JschUtil.getSession("39.1.109", 23, "root", "kee"); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + String command; + BufferedReader reader = null; + ChannelShell channel = (ChannelShell) JschUtil.createChannel(session, ChannelType.SHELL); + channel.setPty(true); + channel.connect(); + InputStream in = channel.getInputStream(); + ThreadUtil.execute(() -> { + IoUtil.readLines(in, CharsetUtil.CHARSET_UTF_8, (LineHandler) System.out::println); + }); + ThreadUtil.execute(() -> { + try { + IoUtil.readLines(channel.getExtInputStream(), CharsetUtil.CHARSET_UTF_8, (LineHandler) System.out::println); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + + OutputStream outputStream = channel.getOutputStream(); + PrintWriter printWriter = new PrintWriter(outputStream); + try { + while ((command = br.readLine()) != null) { + if ("*".equals(command)) { + command = "0x08"; + printWriter.write("0x08".toCharArray()); + printWriter.flush(); + continue; + } + printWriter.println(command); + printWriter.flush(); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + channel.disconnect(); + } + } + }