title: Not able to interact via SSH from a JAVA program
body: <p>I am doing SSH with my linux server via a java program , I am able to execute the commands like shell scripts. But the problem is whenever I am executing a particular shell script it is giving an option to select between yes or no , now from my java console I am selecting yes but this is not actually interacting with the linux server. How to do this job via a java programming? if you have any code spake please share . I am shairing my code for doing the SSH.</p>
  
  <pre><code>    String arr1[]=new String[arr.length];
      ReadConfig rc=new ReadConfig();
      rc.readConfig();
      hostname=rc.hostname;
      username=rc.username;
      password=rc.password;
      for(int i=0;i&lt;arr.length;i++)
      {
          arr1[i]= arr[i];
          System.out.println("the array value "+arr1[i]+" "+i);
      }
  
      try{
           String com=arr1[5].toString().trim();
           System.out.println("  "+com);
          /* Create a connection instance */
  
          conn = new Connection(hostname);
  
          /* Now connect */
                  conn.connect();
  
  
                  /* Authenticate.
           * If you get an IOException saying something like
           * "Authentication method password not supported by the server at this stage."
           * then please check the FAQ.
           */
  
              boolean isAuthenticated = conn.authenticateWithPassword(username, password);
  
  
                  if (isAuthenticated == false)
                      throw new IOException("Authentication failed.");
  
                  /* Create a session */
  
                  sess = conn.openSession();
                 try{
                    sess.execCommand(com);
  
  
                  //obj.append("Pass");
                 }catch(Exception e){
  
  
                     //obj.append("Fail");
                 }
                  //Session sess1 = conn.openSession();
                  System.out.println("Here is some information about the remote host:");
                  InputStream stdout = new StreamGobbler(sess.getStdout());
                  BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
  
                  while (true)
                  {
                      String line = br.readLine();
                      if (line == null)
                          break;
                      System.out.println(line);
                  }
                  /* Show exit status, if available (otherwise "null") */
  
                  System.out.println("ExitCode: " + sess.getExitStatus());
  
      }catch (Exception e) {
          // TODO: handle exception
      }finally{
          /* Close this session */
      //obj.close();
          sess.close();
          /* Close the connection */
  
          conn.close();
      }
  </code></pre>