static async Task <int> MainAsync(CommandArguments args, string doubleDashArg) { if (args.Count == 0 || new[] { "?", "h", "help" }.Any(args.NamedArguments.ContainsKey)) { Console.WriteLine(Prompts.HelpMessage); return(0); } var dumpFileName = (string)args.Requires("d"); var applicationFileName = (string)args.Requires("a"); using (var dumpStream = File.OpenWrite(dumpFileName)) { var monitor = new DumpedStreamMonitorProvider(dumpStream); using (var cin = Console.OpenStandardInput()) using (var bcin = new BufferedStream(cin)) using (var cout = Console.OpenStandardOutput()) using (var cerr = Console.OpenStandardError()) using (var mcin = new MonitoredStream(bcin, monitor.CreateStreamMonitor("STDIN"))) using (var mcout = new MonitoredStream(cout, monitor.CreateStreamMonitor("STDOUT"))) using (var mcerr = new MonitoredStream(cerr, monitor.CreateStreamMonitor("STDERR"))) using (var interceptor = new StdIOInterceptor(applicationFileName, doubleDashArg, mcin, mcout, mcerr)) { await interceptor.StartAsync(); await Task.WhenAny(interceptor.ProcessExitTask, ConsoleInterruptionTask); await interceptor.StopAsync(); } } return(0); }