title: Java program that calls external program behaving asynchronously?
body: <p>All,</p>
  
  <p>I originally had a shell script that called SQLLoader (Oracles data upload tool).</p>
  
  <p>The problem was that SQLLoader takes a plain text password as input so I decided to build a Java application to call SQLLoader internally passing a decrypted password into the command string.</p>
  
  <p>e.g.</p>
  
  <blockquote>
    <p>sqlldr user/pass@DBServer control=../sqlloader.ctl log=sqlloader.log data=mydata.csv</p>
  </blockquote>
  
  <p>So with my java wrapper it became this in my shell script</p>
  
  <pre><code>java -jar sqlloader.jar sqlloader.ctl mydata.csv
  </code></pre>
  
  <p>However a new problem developed when SQLLoader complained there was no file to load. After some head scratching it was discovered that a subsequent command in my shell script seemed to be executing while my java application was still running. Therefore it was behaving asynchronously.</p>
  
  <p>The next command was moving the input file sqlloader was using before it could get a chance to use it. So I put a sleep command in of 20 seconds to give my java application time to run.</p>
  
  <pre><code>java -jar sqlloader.jar sqlloader.ctl mydata.csv
  echo $?
  sleep 20
  if [ $? -ne 0 ]
      then
          echo "SQLLoader failed during execution, please check the log : " 
          mv mydata.csv
  
  else
      echo "SQLLoader successfully processed file : "
      mv mydata.csv
  fi
  </code></pre>
  
  <p>Does anyone know why unix is behaving this way, does Java execute my SQLLoader as a different user/ thread?</p>
  
  <p>This is my java code:</p>
  
  <pre><code>    Runtime Rt;
  Process Prc;
      Prc = Rt.exec("sqlldr user/decryptedpass@DBServer control=../sqlloader.ctl log=sqlloader.log data=mydata.csv);
  system.exit(0);
  </code></pre>
  
  <p>I checked the Runtime Class for anything about it being Asynchronous but couldnt find anything</p>
  
  <p><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html" rel="nofollow">http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html</a></p>
  
  <p>Any theories or suggestions?</p>
  
  <p>Thanks</p>