title: Take commands(password) from string and set as InputStream to Unix servers in Java (JSCH)
body: <p>Almost similar to <a href="https://stackoverflow.com/questions/14846514/change-unix-password-with-java">this</a> topic, but here I am not a superuser to use --stdin.</p>
  
  <p>So I found an other way round, I would open a "shell" in background and give input to shell via a <code>String</code> through <code>InputStream</code></p>
  
  <p>I made a code like below:</p>
  
  <pre><code>String s = "cd bin\n";
  
  byte bb[] = s.getBytes();
  
  InputStream intt = new ByteArrayInputStream(bb);
  
  channel.setInputStream(new FilterInputStream(intt) {
      public int read(byte[] b, int off, int len) throws IOException {
          return in.read(b, off, (len &gt; 1024 ? 1024 : len));
      }
  });
  </code></pre>
  
  <p>Now this works perfectly when I want to execute only one command but I want to give multiple commands, for which I am facing issue.</p>
  
  <p>Any suggestions?</p>
  
  <p>Regards,</p>
  
  <p>Ishan</p>