title: Send Enter Key in a SSH Connector
body: <p>I am trying to run some commands on a  Linux machine using a SSH connector written in Java.</p>
  
  <p>I am using Jsch library to run commands via SSH.</p>
  
  <p>The problem is on the end point which is Red hat Linux box :- </p>
  
  <p>Once i execute a su - command 
  There is a small perl program which kicks off :- Asking for some information</p>
  
  <p>Something like :-</p>
  
  <pre><code>SHELL# su -
  Enter some info
  Info
  Are you ok to proceed (y/n) y
  SHELL#
  </code></pre>
  
  <p>I am successfully able to enter the info part from the code. But after that </p>
  
  <p>Are you ok to proceed (y/n) y</p>
  
  <p>MY code crashes and it looks like the y command is not taken properly.</p>
  
  <p>I was wondering if i should send Y + "enter key" from the code to make it work.
  How can i achieve that?</p>
  
  <p>Here is the main logic of the code :- </p>
  
  <pre><code>import com.jcraft.jsch.Channel;
      import com.jcraft.jsch.ChannelExec;
      import com.jcraft.jsch.JSch;
      import com.jcraft.jsch.JSchException;
      import com.jcraft.jsch.Session;
  
  
  Channel channel;
  Session session;
  
                     JSch jsch = new JSch();
                     SSHUserInfo sshUserInfo = new SSHUserInfo();
          sshUserInfo.setTrust(true);
          sshUserInfo.setPassword(loginPassword);
          sshUserInfo.setName(loginUserName);
          session = jsch.getSession(loginUserName, host, port);
          session.setUserInfo(sshUserInfo);
          session.connect();
  
  
                 channel = session.openChannel(SSH_TYPE_SHELL);
  
          InputStream in = channel.getInputStream();
          OutputStream out = channel.getOutputStream();
          channel.connect();
  
                 InputStream in = channel.getInputStream();
          OutputStream out = channel.getOutputStream();
          channel.connect();
  
  
          out.write(("su -" + "\n").getBytes());
              out.write(("info" + "\n").getBytes());
          out.write(("y" + "\n").getBytes());
  </code></pre>
  
  <p>Any help appreciated.</p>