session - java sshd multiple command -


if have actual solution problem appreciate it. far implementation have used close session 1 of channel "connected" ever means. need able script ssh interaction meaning need result of operation still alive channel i'm not looking command "cmd1;cmd2;cmd3" type ..

the best example can think of if trying browse trough file system.

if each command new session going going no since @ each new session go square one.

in command line ssh session remain open when type operation why java implementation differ approach beyond me. next step if cant find answer use command shell java , interacting there instead of using java ssh libraries..

  public void connect() {     session session;     try {         session = createconnectedsession();         java.util.logging.logger.getlogger("test").log(level.info,"isconnected "+session.isconnected());         bytearrayoutputstream output = new bytearrayoutputstream();         channel channel = session.openchannel("shell");          channel.setoutputstream(output);          printstream ps = new printstream(channel.getoutputstream(), true);         // inputstream = new inputstream(channel.getinputstream());         channel.connect();         sleep();         java.util.logging.logger.getlogger("test").log(level.info,"isconnected "+session.isconnected());         stack<string> mstack = getcommandstack();         //readchannel(channel);         while (!mstack.isempty()) {             string cmd = mstack.pop();             java.util.logging.logger.getlogger("test").log(level.info,"sending command "+cmd);             ps.println(cmd);             sleep();             system.out.println(output.tostring());             java.util.logging.logger.getlogger("test").log(level.info,"command result"+output.tostring());             sleep();             // system.out.println(output.tostring());             ps.flush();         }          channel.disconnect();         session.disconnect();     } catch (jschexception e) {         // todo auto-generated catch block         e.printstacktrace();     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();     }  } 

}


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -