Visual Basic (Declaration) | |
---|---|
Public Function New( _ ByVal executable As String _ ) |
C# | |
---|---|
public ProcessRunner( string executable ) |
Parameters
- executable
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.NET | Copy 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 |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
ProcessRunner ClassProcessRunner Members
Overload List