-1
에 연결하면 Java에 익숙해 져 도움이 필요합니다. jsch 라이브러리를 사용하여 원격 Linux 시스템에 SHH 연결을 만듭니다. 다음 코드에서는 JSCH 작성자의 자습서에서 제공되는 셸 통신을 볼 수 있으며 cmd 창에서 직접 통신합니다. cmd 창에서 명령을 입력하면 cmd 창에 결과가 표시됩니다.JSch의 setInputStream 및 setOutputStream을 jTextField의
String user = "username";
String host = "hostname";
session session=jsch.getSession(user, host, 22);
String passwd = JOptionPane.showInputDialog("Enter password");
session.setPassword(passwd);
Channel channel=session.openChannel("shell");
session.connect();
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
어떻게 jTextField1 및 jTextField2에 다음 두 줄을 연결할 수 있습니까? 예를 들어 jTextField1에서 명령을 sen하고 jTextField2에서 결과를 얻고 싶습니다.
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
는 예를
String ls = "ls \n"; // here i am passing a string to stream, you can pass as you desire
InputStream in = new ByteArrayInputStream(ls.getBytes("UTF-8"));
channel2.setInputStream(in);//you passed the string as input
ByteArrayOutputStream out = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(out);
channel2.setOutputStream(ps);
String result = out.toString();//here we get output to a string which you can add to your file.
.FOR 원하는 스트림을 제공 할 수 있습니다 대신 System.in의 고급