CSharpTest.Net
ProcessRunner Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Processes Namespace : ProcessRunner Class

Glossary Item Box

Creates/Spawns a process with the standard error/out/in all mapped. Subscribe to the OutputReceived event prior to start/run to listen to the program output, write to the StandardInput for input.

Syntax

Visual Basic (Declaration) 
Public Class ProcessRunner 
   Implements IRunner 
C# 
public class ProcessRunner : IRunner  

Example

Library/Library.Test/TestProcessRunner.cs

C#Copy Code
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); }
VB.NETCopy Code
Dim tempfile As String = Path.GetTempFileName()
Try
    Environment.CurrentDirectory = Path.GetDirectoryName(FileUtils.FindFullPath("cmd.exe"))
    Dim runner As 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 generatedExceptionName As InvalidOperationException
    End Try

    Assert.IsFalse(runner.WaitForExit(TimeSpan.FromSeconds(1), False))
    runner.Kill()
    Dim output As String = File.ReadAllText(tempfile).Trim()
    Assert.AreEqual("Hello", output)
Finally
    File.Delete(tempfile)
End Try

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Processes.ProcessRunner

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys