private static void RunAndCaptureOutputTo(string capturePath) { var oldOut = Console.Out; using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); for (int i = 1; i < 42; i++) { var runner = new GameRunner(new Random(i)); runner.DoMain(new string[] { }); } File.WriteAllText(capturePath, sw.ToString()); } Console.SetOut(oldOut); }