I'm new worker with JSch API, I've make a class witch work properly, but my concern is to return the result of launched command in a string variable, currenly, i don't know why but it's not working whe I do this.setTheResult(cmdrslt). but when I do System.out.println(text).
Please can someone help me on this.
public String processTheCmd() {
try{
this.channel=this.session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
System.out.println("Canal ouvert avec succès");
InputStream in=channel.getInputStream();
channel.connect();
System.out.println("connection réussie avec succès");
byte[] tmp=new byte[1024];
while(true){
while(in.available()>0){
int i=in.read(tmp, 0, 1024);
if(i<0)break;
String cmdrslt= new String(tmp, 0, i);
this.setTheResult(cmdrslt);
// System.out.println(text);
System.out.println("résultat mis dans le packet normalement");
closeChanelAndSession();
}
}
}catch (JSchException e){System.out.println(e);}
catch (IOException e){System.out.println(e);}
return this.getTheResult();
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I'm new worker with JSch API, I've make a class witch work properly, but my concern is to return the result of launched command in a string variable, currenly, i don't know why but it's not working whe I do this.setTheResult(cmdrslt). but when I do System.out.println(text).
Please can someone help me on this.