ProcessRunner ClassDelta Engine Documentation
Starts a command line process with given argument and optional timeout. Supports events or can be used synchronously with checking Error or Output afterwards. Exceptions are thrown when things go bad (ExitCode not 0 or process times out). View code on GitHub
Inheritance Hierarchy

System Object
  DeltaEngine.Core ProcessRunner

Namespace: DeltaEngine.Core
Assembly: DeltaEngine (in DeltaEngine.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class ProcessRunner

The ProcessRunner type exposes the following members.

Constructors

  NameDescription
Public methodProcessRunner
Initializes a new instance of the ProcessRunner class
Top
Methods

  NameDescription
Public methodClose
Protected methodSetupStartInfo
Public methodStart
Top
Fields

  NameDescription
Protected fieldtimeoutInMs
Top
Properties

  NameDescription
Public propertyArgumentsLine
Public propertyErrors
Public propertyFilePath
Public propertyIsExitCodeRelevant
Public propertyIsWaitingForExit
Public propertyOutput
Public propertyWorkingDirectory
Top
Events

  NameDescription
Public eventErrorOutputEvent
Public eventStandardOutputEvent
Top
Remarks

Tests: DeltaEngine.Tests.Core.ProcessRunnerTests
Examples

4 unit tests call DeltaEngine.Core.ProcessRunner
[Test]
public void DefaultWorkingDirectory()
{
    var processRunner = new ProcessRunner("cmd.exe", "/c dir");
    Assert.AreEqual(Environment.CurrentDirectory, processRunner.WorkingDirectory);
}
[Test]
public void ChangingWorkingDirectory()
{
    var processRunner = new ProcessRunner("cmd.exe", "/c dir");
    processRunner.Start();
    var outputWithDefaultWorkingDirectory = processRunner.Output;
    processRunner.WorkingDirectory = @"C:\";
    processRunner.Start();
    var outputWithDefinedWorkingDirectory = processRunner.Output;
    Assert.AreNotEqual(outputWithDefaultWorkingDirectory, outputWithDefinedWorkingDirectory);
}
[Test]
public void StandardOutputEvent()
{
    var logger = new MockLogger();
    var processRunner = new ProcessRunner("cmd.exe", "/c dir");
    processRunner.StandardOutputEvent +=
        outputMessage => logger.Write(Logger.MessageType.Info, outputMessage);
    processRunner.Start();
    Assert.IsTrue(
        logger.LastMessage.Contains("Dir(s)") || logger.LastMessage.Contains("Verzeichnis(se)"),
        logger.LastMessage);
}
See Also