title: How do I execute an executable file from within a java file on linux?
body: <p>I am trying to execute an executable file and a perl script from within a java program. I have found many topics similar to this but most of them refer to windows. I know java is platform independent and it should work anyways but it doesn't. The solution I have tried already is the one based on the java Runtime and it's exec method. It works just fine on windows but since I'm porting my program on linux I need to adapt it. As I said I need to execute an executable file that I have compiled and was written in c++ which it looks like it's working but it finishes executing with an exit value of 1. I have no idea what it means but on windows it exits with 0 and that's how it should be on linux as well (?!?!). The pearl script on the other hand does not start at all. I use the command "perl script.pl" and it exits with a value of 255. Needless to say, it doesn't do what it's supposed to.</p>
  
  <p>Does anybody know another way to execute these files? Or maybe where I am wrong with my implementation?</p>
  
  <p>here's the code if you want to take a look at it:
  This is the one for the perl script</p>
  
  <pre><code>public static void main(String[] args){
      System.out.println("Starting");
      try{
          String[] cmd = {"perl", "cloc-1.53.pl"};
          Process pr = Runtime.getRuntime().exec(cmd);
          BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
  
          String line=null;
  
          while((line=input.readLine()) != null) {
              System.out.println(line);
          }
  
          int exitVal = pr.waitFor();
          System.out.println("Exit code: " + exitVal);
      } catch (Throwable t){
          t.printStackTrace();
      }
  }
  </code></pre>
  
  <p>For the compiled file I change this:</p>
  
  <pre><code>String[] cmd = {"perl", "cloc-1.53.pl"};
  </code></pre>
  
  <p>with:</p>
  
  <pre><code>String cmd = "./UCC";
  </code></pre>