title: WiX/MSI: Redirect stdout to file, type 50 custom action
body: <p>I have a WiX installer all rigged up to run <code>SqlPackage.exe</code> to deploy some installed <code>.dacpac</code>-packaged SQL applications to a database. Actually deploying the database files as follows will succeed:</p>
  
  <pre><code>&lt;Property Id="CONNSTRING" Value="Data Source=localhost;Integrated Security=True;Initial Catalog=MPQS-DACPAC" /&gt;
  &lt;Property Id="SQLPACKAGEPATH" Value="C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /&gt;
  &lt;CustomAction Id="DeployDatabase" Property="SQLPACKAGEPATH"
                ExeCommand='/Action:Publish /tcs:"[CONNSTRING]" /sf:"[#My.Database.dacpac]" /p:BackupDatabaseBeforeChanges=True /p:RegisterDataTierApplication=True'
                Return="check" Execute="deferred" Impersonate="yes" /&gt;
  
  &lt;InstallExecuteSequence&gt;
    &lt;Custom Action="DeployDatabase" After="DuplicateFiles"&gt;NOT REMOVE&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;
  </code></pre>
  
  <p>...and I can watch the output in the presented console window, mid-install.</p>
  
  <p>However, it doesn't always succeed; for example, <code>CONNSTRING</code> can be specified in a dialog and may be incorrect. If there are errors, they appear for an instant, then the console closes and I get a 1722 error in the logs.</p>
  
  <p>To capture the console output, I have tried:</p>
  
  <pre><code>&lt;CustomAction Id="DeployDatabase" Property="SQLPACKAGEPATH"
                ExeCommand='/Action:Publish /tcs:"[CONNSTRING]" /sf:"[#My.Database.dacpac]" /p:BackupDatabaseBeforeChanges=True /p:RegisterDataTierApplication=True &amp;gt; "[DBLogs]test.log"'
                Return="check" Execute="deferred" Impersonate="yes" /&gt;
  </code></pre>
  
  <p>The <code>&amp;gt; "[DBLogs]test.log"</code> on the end should (theoretically) redirect output to a file at that location, but instead, the installer fails out at the moment the console window is shown. It appears that no text is displayed in the console in the instant it is presented.</p>
  
  <p>The kicker is: I can copy the command that is logged with the error (with the <code>&amp;gt;</code> properly resolved to <code>&gt;</code>), paste it into my own <code>cmd</code> window, and it will execute and log.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>And more importantly: what can I do to execute this command <em>and</em> save <code>stdout</code>+<code>stderr</code> to a logfile?</p>
  
  <p>Note: I have also tried this with the type 34 syntax (this way resolves to a type 50). Both exhibit the same behavior.</p>