Example #1
0
 /// <summary> Kills the process if it is still running </summary>
 public void Kill()
 {
     _runner.Kill();
 }
		public void TestKill()
		{
			string tempfile = Path.GetTempFileName();
			try
			{
				Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"));
				ProcessRunner runner = new ProcessRunner("cmd.exe");
				Assert.IsFalse(runner.IsRunning);
				runner.Kill(); // always safe to call

				runner.Start("/K", "ECHO Hello > " + tempfile);
				Assert.IsTrue(runner.IsRunning);

				try //make sure we can't start twice.
				{
					runner.Start("/C", "ECHO", "HELO");
					Assert.Fail();
				}
				catch (InvalidOperationException)
				{ }

				Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), false));
				runner.Kill();
				string output = File.ReadAllText(tempfile).Trim();
				Assert.AreEqual("Hello", output);
			}
			finally
			{ File.Delete(tempfile); }
		}