title: Is it possible to have a WPF application print console output?
body: <p>I have a simple WPF application. Under normal use, App.xaml will launch MainWindow.xaml. But I would like to set it up so that if it is invoked with a special command line argument, that it will function as a console application instead.</p>
  
  <p>So here's roughly what my App.xaml.cs file looks like:</p>
  
  <pre><code>using System;
  
  namespace MyProject
  {
      public partial class App : Application
      {
          public void App_OnStartup(object sender, StartupEventArgs e)
          {
              if (e.Args.Length == 1 &amp;&amp; e.Args[0].Equals("/console"))
              {
                  Console.WriteLine("this is a test");
                  Environment.Exit(0);
              }
              else
              {
                  var mainWindow = new MainWindow();
                  mainWindow.Show();
              }
          }
      }
  }
  </code></pre>
  
  <p>I would expect that when I run <code>MyProject.exe /console</code> from the command line, it would print the string "this is a test". But right now it doesn't print anything. How can I get it to work?</p>