use of com.jn.langx.commandline.streamhandler.OutputAsStringExecuteStreamHandler in project agileway by fangjinuo.
the class SshCommandLineExecutorTest method showResult.
private static void showResult(SshCommandLineExecutor executor) {
DefaultExecuteResultHandler resultHandler = (DefaultExecuteResultHandler) executor.getResultHandler();
if (resultHandler.hasResult()) {
Throwable exception = resultHandler.getException();
if (exception != null) {
logger.error(exception.getMessage(), exception);
} else {
OutputAsStringExecuteStreamHandler output = (OutputAsStringExecuteStreamHandler) executor.getStreamHandler();
String str = output.getOutputContent();
logger.info(str);
}
}
}
use of com.jn.langx.commandline.streamhandler.OutputAsStringExecuteStreamHandler in project agileway by fangjinuo.
the class SshCommandLineExecutorTest method testExec.
private void testExec(SshConnectionFactory connectionFactory, AbstractSshConnectionConfig connectionConfig) throws SshException, IOException {
// connectionConfig.setHost("192.168.234.128");
connectionConfig.setHost("192.168.1.70");
connectionConfig.setPort(22);
connectionConfig.setUser("fangjinuo");
connectionConfig.setPassword("fjn13570");
SshConnection connection = connectionFactory.get(connectionConfig);
SshCommandLineExecutor executor = new SshCommandLineExecutor(connection);
executor.setWorkingDirectory(new File("~/.java"));
OutputAsStringExecuteStreamHandler output = new OutputAsStringExecuteStreamHandler();
executor.setStreamHandler(output);
executor.execute(CommandLine.parse("ifconfig"));
showResult(executor);
System.out.println("====================================");
executor.execute(CommandLine.parse("ls -al"));
showResult(executor);
connection.close();
}
Aggregations