I've been working on automating our build processes and wanted to come up with a painless way to run unit tests on a regular basis. To that end I've thrown together a simple app that examines the project files and prepares a list of solutions to test. The prototype works in that the tests are executed with the expected results, but as soon as I try to redirect my output the app bombs on the Process.Start call, complaining that a file could not be found.
I've tried several iterations on what I've seen done elsewhere, including several posts here, but I have yet to get this to work properly.
This works:
Private Function WTF(ByVal aWorkingDirectory As String, ByVal aFileName As String, ByVal aArguments As String) As Boolean
Dim lProcess As New Process()
With lProcess
.StartInfo.WorkingDirectory = aWorkingDirectory
.StartInfo.FileName = aFileName
.StartInfo.Arguments = aArguments
End With
lProcess.Start()
lProcess.WaitForExit()
End Function
This does not work:
Private Function WTF(ByVal aWorkingDirectory As String, ByVal aFileName As String, ByVal aArguments As String) As Boolean
Dim lProcess As New Process()
With lProcess
.StartInfo.CreateNoWindow = True
.StartInfo.UseShellExecute = False
.StartInfo.RedirectStandardOutput = True
.StartInfo.RedirectStandardError = True
.StartInfo.WorkingDirectory = aWorkingDirectory
.StartInfo.FileName = aFileName
.StartInfo.Arguments = aArguments
End With
lProcess.EnableRaisingEvents = True
AddHandler lProcess.OutputDataReceived, AddressOf blah
AddHandler lProcess.ErrorDataReceived, AddressOf blah
lProcess.Start()
lProcess.BeginOutputReadLine()
lProcess.BeginErrorReadLine()
lProcess.WaitForExit()
End Function
Private Shared Sub blah(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs)
Console.WriteLine(e.Data)
End Sub
"System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start()... yadda yadda yadda"
Any suggestions for solving this using this model would be appreciated.