title: java Runtime.exec to run shell script - cannot open file
body: <p>I am using Runtime.getRuntime().exec() to run a shell script from java code.</p>
  
  <pre><code>    String[] cmd = {"sh",  "build.sh", "/Path/to my/sh file"};
      try{
          Process proc = Runtime.getRuntime().exec( cmd );
      }
      catch(Exception e){
          System.out.println("Exception is:"+e);
      }
  </code></pre>
  
  <p>It gives me the following output in console:</p>
  
  <pre><code>sh: Can't open build.sh
  </code></pre>
  
  <p>Am I following some wrong approach here? Cannot make out why his happens.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Based on the comment here, I have modified the <code>String[] cmd = {"sh",  "build.sh", "/Path/to my/sh file"};</code> to <code>String[] cmd = {"sh",  "/Path/to my/sh file/build.sh", "/Path/to my/sh file"};</code> . Now the problem is this script need to be executed from a particular path. When I execute this script from command prompt, I first change the directory to that path and execute it. How should I modify this code?</p>