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

Glossary Item Box

Runs the process and returns the exit code.

Syntax

Visual Basic (Declaration) 
Public Overloads Function Run() As Integer
C# 
public int Run()

Example

Library/Library.Test/TestProcessRunner.cs

C#Copy Code
using (TempDirectory dir = new TempDirectory())
using (ProcessRunner runner = new ProcessRunner("cmd.exe", "/C", "echo CD"))
{
    List<string> lines = new List<string>();
    runner.OutputReceived += delegate(Object o, ProcessOutputEventArgs e) { lines.Add(e.Data); };

    Assert.AreNotEqual(dir.TempPath, runner.WorkingDirectory);
    runner.WorkingDirectory = dir.TempPath;
    Assert.AreEqual(dir.TempPath, runner.WorkingDirectory);
    
    int exitCode = runner.Run();
    Assert.AreEqual(0, exitCode);
    Assert.AreEqual(dir.TempPath.TrimEnd('\\', '/'), lines[0].TrimEnd('\\', '/'));
}
VB.NETCopy Code
Using dir As New TempDirectory()
    Using runner As New ProcessRunner("cmd.exe", "/C", "echo CD")
        Dim lines As New List(Of String)()
        runner.OutputReceived += Function(o As [Object], e As ProcessOutputEventArgs) Do
            lines.Add(e.Data)
        End Function

        Assert.AreNotEqual(dir.TempPath, runner.WorkingDirectory)
        runner.WorkingDirectory = dir.TempPath
        Assert.AreEqual(dir.TempPath, runner.WorkingDirectory)

        Dim exitCode As Integer = runner.Run()
        Assert.AreEqual(0, exitCode)
        Assert.AreEqual(dir.TempPath.TrimEnd("\"C, "/"C), lines(0).TrimEnd("\"C, "/"C))
    End Using
End Using

Requirements

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

See Also

Generated with Document! X 2011 by Innovasys