java - JSch shell returns into StringArray -


i trying relearn java after 10 years of not touching it. want create library using jsch other apps looking write. have connections ironed out using stdin , stdout right now. looking have method accepts single command in string , returns arraylist results.

any assistance great!

//this vars in class. private jsch _jsch; private session _session; private channel _channel; 

here connection method

public boolean connect () throws jschexception {     try {         _jsch = new jsch();         _session = _jsch.getsession(_user, _hostname, _port);               _session.setpassword(_password);         _session.setconfig("stricthostkeychecking", "no");            _channel = _session.openchannel("shell");          //((channelshell)_channel).setptytype("vt100");          _channel.setinputstream(bais);         _channel.setoutputstream(baos);         _channel.connect(3000);                          }//try connect     catch (jschexception ex)     {         throw ex;     }     return true; } 

the goal once open connection can send method command , return results in array. act based on results , send more commands. don't want close connection each time build on commands come before it. not sure how work inputs , output streams enough results looking for. if can assist filling out following method, grateful.

public list<string> executecommand (string command) {     //run command existing connection     //get returned lines array list , return list } 

thanks

here's example of running local process , creating return arraylist filled line line output process. whilst it's not want, should give idea.

public list<string> executecommand (string command) {     runtime r = runtime.getruntime();     process p = r.exec(command);     p.waitfor();     bufferedreader b = new bufferedreader(new inputstreamreader(p.getinputstream()));     string line = "";     arraylist<string> output = new arraylist<string>();     while ((line = b.readline()) != null) {         output.add(line);     }     return output; } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -