title: Reading output file of SQLCMD using Java
body: <p>I am executing a bunch of SQL scripts and trying to read the output log file, looking for errors, after each file is executed.</p>
  
  <p>Here's how I execute the script.</p>
  
  <pre><code>String strCommand = "sqlcmd -S SERVERNAME -d DBNAME -U USERNAME -P PASSWORD -r0 -i \"SCRIPT.sql\" 2&gt; \"OUTPUT.LOG\" 1&gt; NULL";
  Process process = Runtime.getRuntime().exec(strCommand);
  process.waitFor();
  </code></pre>
  
  <p>I've redirected the standard output to <code>NULL</code> and errors to the log file. Immediately following the execution of the above statements, I try to read the contents of the OUTPUT.LOG file, using <code>File Reader</code> and <code>BufferedReader</code>. An exception is thrown when trying to open the OUTPUT.LOG file.</p>
  
  <blockquote>
    <p>(The system cannot find the file specified)</p>
  </blockquote>
  
  <p>I check the path where the file should be saved, and needless to say, it isn't there. When I try to manually execute the command via Command Prompt, it works and writes the log file with errors, as expected. What am I doing wrong?</p>