Example #1
0
 public void can_start_process_as_child()
 {
     using (var subject = new ProcessHost("./ExampleNoninteractiveProcess.exe", Directory.GetCurrentDirectory()))
     {
         subject.StartAsChild("print hello world");
         Thread.Sleep(500);
         var output = subject.StdOut.ReadAllText(Encoding.Default);
         //var output = subject.StdOut.ReadToTimeout(Encoding.Default, TimeSpan.FromSeconds(10));
         Assert.That(output, Is.StringStarting("hello world"));
     }
 }
Example #2
0
		static int Main(string[] args)
		{
            if (args.Length > 0 && args[0] == "wait")
            {
                for(;;)
                {
	                Thread.Sleep(1000);
                }
            }

            if (args.Length > 0 && args[0] == "print")
            {
	            Console.WriteLine(string.Join(" ", args.Skip(1)));
                return 0;
            }

            if (args.Length > 0 && args[0] == "envarg")
            {
                var envargs = Environment.GetEnvironmentVariables();
                foreach (DictionaryEntry envarg in envargs)
                {
                    Console.WriteLine(envarg.Key + " = " + envarg.Value);
                }
                return 0;
            }

		    if (args.Length > 0 && args[0] == "spawn")
		    {
                // spawn a new process, and output its ID. Then wait forever
		        var ph = new ProcessHost("ExampleNoninteractiveProcess.exe", "");
                ph.StartAsChild("wait");
		        Console.WriteLine(ph.ProcessId());
		        for(;;)
		        {
		            Thread.Sleep(1000);
		        }
		    }

            
            if (args.Length > 1 && args[0] == "return")
            {
                return int.Parse(args[1]);
            }

			Console.WriteLine(StdOutMsg);
            using (var stdErr = Console.OpenStandardError())
            {
                var msgBytes = Encoding.ASCII.GetBytes(StdErrMsg);
                stdErr.Write(msgBytes, 0, msgBytes.Length);
            }

            return 0;
		}