2 using System.Diagnostics;
3 using System.Reflection;
6 namespace ToManyOpenHandles
10 static void Main(string[] args)
14 WriteStuffMode(args[0]);
20 Console.WriteLine("Success!!!!");
23 private static void WriteStuffMode(string counter)
25 Console.WriteLine("Run {0} {1}", counter, Console.ReadLine ());
28 private static void RunStuffMode()
30 for (int i = 0; i < 100; i++)
32 Execute(Assembly.GetExecutingAssembly().Location, i.ToString());
36 public static void Execute(string exe, string exeArgs)
38 using (var p = NewProcess(exe, exeArgs))
40 p.OutputDataReceived += (sender, args) =>
42 if (args.Data != null)
43 Console.WriteLine(args.Data);
45 p.ErrorDataReceived += (sender, args) =>
47 if (args.Data != null)
48 Console.Error.WriteLine(args.Data);
52 p.BeginOutputReadLine();
53 p.BeginErrorReadLine();
55 p.StandardInput.WriteLine ("hello");
65 public static Process StartProcess(string filename, string arguments)
67 var p = NewProcess(filename, arguments);
73 static Process NewProcess(string exe, string args)
80 CreateNoWindow = true,
81 UseShellExecute = false,
82 RedirectStandardOutput = true,
83 RedirectStandardInput = true,
84 RedirectStandardError = true,