CSharpTest.Net
ProcessRunner Constructor(String)
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Processes Namespace > ProcessRunner Class > ProcessRunner Constructor : ProcessRunner Constructor(String)

executable

Glossary Item Box

Creates a ProcessRunner for the given executable

Syntax

Visual Basic (Declaration) 
Public Function New( _
   ByVal executable As String _
)
C# 
public ProcessRunner( 
   string executable
)

Parameters

executable

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

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys