1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public void executerScript(String script) {
List<String> result = new ArrayList<String>();
try {
JSch jsch = new JSch();
Session session = jsch.getSession(USER, ADRESSE);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(PASSWORD);
session.connect();
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
InputStream in = channelExec.getInputStream();
channelExec.setCommand("sh " + script);
channelExec.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null){
result.add(line);
}
channelExec.disconnect();
session.disconnect();
} catch (Exception e) {
System.out.println(e);
}
System.out.println(result);
} |
Partager