title: How to run a SQL script in tsql
body: <p>I'm using tsql (installed with FreeTDS) and I'm wondering if there's a way to run a SQL script in tsql from the command line and get the result in a text file.</p>
  
  <p>For example, in psql I can do:</p>
  
  <pre><code>psql -U username -C "COPY 'SELECT * FROM some_table' to 'out.csv' with csv header"
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>psql -U username -C "\i script.sql"
  </code></pre>
  
  <p>And in script.sql do:</p>
  
  <pre><code>\o out.csv
  SELECT * FROM  some_table;
  </code></pre>
  
  <p>Is there a way for doing this in tsql? I have read the linux man page and search everywhere but I just don't find a way.</p>