title: Running Linux commands on Java through JSch
body: <p>I'm establishing an SSH connection through JSch on Java and everything seemed to be working fine, until I tried to run this .sh file. The shell script's name is <code>repoUpdate.sh</code> and it's very simple:</p>
  <pre class="lang-sh prettyprint-override"><code>echo  ' ****Repository update****'
  echo  ' Location: /home/cissys/repo/'
  echo -e ' Command: svn update /home/cissys/repo/2.3.0'
  
  svn update /home/cissys/repo/2.3.0
  </code></pre>
  <p>This is the output I get directly on the linux console with the proper response of the command:</p>
  <pre class="lang-none prettyprint-override"><code>[cissys@dsatelnx5 ~]$ repoUpdate.sh
   ****Repository update****
   Location: /home/cissys/repo/
   Command: svn update /home/cissys/repo/2.3.0
  
  At revision 9432.
  </code></pre>
  <p>Now, here's the Java code of my method with the SSH connection that tries to call this same file</p>
  <pre><code>public void cmremove()
  {
      try
      {
          JSch jsch = new JSch();
          Session session = jsch.getSession(user, host, port);
          UserInfo ui = new SUserInfo(pass, null);
          session.setUserInfo(ui);
          session.setPassword(pass);
          session.connect();
          
          ChannelExec channelExec = (ChannelExec)session.openChannel(&quot;exec&quot;);
          
          InputStream in = channelExec.getInputStream();
          
          channelExec.setCommand(&quot;./repoUpdate.sh&quot;);
          channelExec.connect();
          
          BufferedReader reader = new BufferedReader(new InputStreamReader(in));
          String line;
          int index = 0;
          
          while ((line = reader.readLine()) != null)
          {
              System.out.println(++index + &quot; : &quot; + line);
          }
          
          channelExec.disconnect();
          session.disconnect();
          
          System.out.println(&quot;Done!&quot;);
      }
      catch(Exception e)
      {
          System.err.println(&quot;Error: &quot; + e);
      }
  }
  </code></pre>
  <p>And the response I get is the following:</p>
  <pre class="lang-none prettyprint-override"><code>run:
  1 :  ****Repository update****
  2 :  Location: /home/cissys/repo/
  3 :  Command: svn update /home/cissys/repo/2.3.0
  Done!
  BUILD SUCCESSFUL (total time: 2 seconds)
  </code></pre>
  <p>with no output or signs of execution on the <code>svn</code> command (<code>At revision 9432</code>) whatsoever.</p>
  <p>I'm thinking it may be closing the session at some point, not letting the command execute properly. If the <code>updateRepo.sh`` file would've had something like </code>cp test.txt test_2.txt`, it would do it with no problem. But i only have this problem with this and some other specific .sh files.</p>
  <p>Any help would be appreciated.</p>