/// <summary> /// Thread main function that creates processes. The child /// processes don't output to the console. Instead, we swallow /// their output with a null pipe. /// </summary> private static void ProcessCreationMainWithNoOutput() { int id = Interlocked.Increment(ref idGenerator) - 1; NullPipeControl.Imp : START !control = StartNullPipe(); DirectoryServiceContract.Imp !directoryService = DirectoryService.NewClientEndpoint(); // Wait for the signal evtGate.WaitOne(); // Create many processes Process[] children = new Process[iterations]; try { for (int i = 0; i < iterations; i++) { UnicodePipeContract.Imp !childStdInImp; UnicodePipeContract.Exp !childStdInExp; UnicodePipeContract.NewChannel(out childStdInImp, out childStdInExp); UnicodePipeContract.Imp !childStdOutImp = CreateNullPipeClient(control); //Manifest manifest; children[i] = Binder.CreateProcess(directoryService, new string[1] { commandLine }, childStdInExp, childStdOutImp); delete childStdInImp; if (children[i] == null) { throw new ProcessCreateException("Failed to create process"); } ((!)children[i]).Start(); if (id == 0) { Console.Write('.'); } } } finally { delete directoryService; delete control; } // Wait for all children to finish for (int i = 0; i < children.Length; i++) { ((!)children[i]).Join(); } }
//[ShellCommand("StartProcess", "tests lib routine to start process with Manifest")] internal static int AppMain(Parameters !config) { DirectoryServiceContract.Imp ds = null; if (config.nsRef != null) { ds = config.nsRef.Acquire(); } if (ds == null) { throw new Exception("Unable to acquire handle to the Directory Service root"); } ds.RecvSuccess(); // Make ourselves a new output pipe UnicodePipeContract.Exp !newOutputExp; UnicodePipeContract.Imp !newOutputImp; UnicodePipeContract.NewChannel(out newOutputImp, out newOutputExp); // Retrieve our real stdOut and start using the one we just created // instead UnicodePipeContract.Imp stdOut = ConsoleOutput.Swap(newOutputImp); if (stdOut == null) { Console.WriteLine("runtests expects a STDOUT pipe"); delete newOutputExp; delete ds; return(1); } // Use a mux to splice our own output together with the child // processes we will run. PipeMultiplexer !outputMux = PipeMultiplexer.Start(stdOut, newOutputExp); string[] args = config.Args; if (args != null && args[0] != null) { RunProcess(ds, args, outputMux); } outputMux.Dispose(); delete ds; return(0); }