title: Execute sh file from Java
body: <p>I am trying to execute an sh file via the following code (CentOS machine btw)</p>
  
  <pre><code>Runtime.getRuntime().exec("sh " + file.getPath());
  </code></pre>
  
  <p>I use this code for windows and it works fine</p>
  
  <pre><code>Runtime.getRuntime().exec("cmd /c start " + file.getPath());
  </code></pre>
  
  <p>Could it be because I'm using Screen in the .sh file? I am also using the java command to start the server so maybe I need to include these?</p>
  
  <p>Here are the contents of the sh file</p>
  
  <pre><code>#!/bin/sh
  BINDIR=$(dirname "$(readlink -fn "$0")")
  cd "$BINDIR"
  screen -S PrivateServer java -Xms2048M -Xmx2048M -jar somejar.jar -o true
  </code></pre>
  
  <p>I am also running this code from a shutdown hook, could this be the issue? This is intended because the software is a game server and it is intended so that the user can use a restart command or have it auto restart without needing to setup anything them self.</p>
  
  <p>Edit: I decided to output the errors to a text file and found this "Must be connected to a terminal." any ideas? I believe this is an issue to do with using screen.</p>