日期:2014-05-16 浏览次数:20358 次
exceChannel = (ChannelExec)session.openChannel("exec"); is = exceChannel.getInputStream(); errStream = exceChannel.getErrStream(); exceChannel.setCommand(command); exceChannel.connect(); StringBuilder builder = new StringBuilder(); while (true) { byte[] bytes = new byte[1024]; while(is.available()>0){ is.read(bytes, 0, bytes.length); builder.append(new String(bytes)); } while(errStream.available()>0){ errStream.read(bytes, 0, bytes.length); log.error(new String(bytes)); } log.debug("value:"+builder.toString()); if (exceChannel.isClosed()) { log.debug("exit-status: " + exceChannel.getExitStatus()); break; } // try { // Thread.sleep(1000); // } catch (Exception e) { // } exceChannel.disconnect(); }
2013-01-23 16:32:29,093 DEBUG [main] (SshCommandTool.java:112) - value:Microsoft Windows [Version 5.2.3790] (C) Copyright 1985-2003 Microsoft Corp. D:\sftp\ICW\home\ssh2>
2013-01-23 16:33:50,125 DEBUG [main] (SshCommandTool.java:112) - value:java version "1.6.0_38" Java(TM) SE Runtime Environment (build 1.6.0_38-b05) Java HotSpot(TM) Client VM (build 20.13-b02, mixed mode, sharing)