Question

I have a piece of code that calls MSTEST with multiple arguments defining a specific set of tests to run and an environment to run it in. Currently the code looks like this (a bit messy but it works):

Process.Start(Environment.GetEnvironmentVariable("VS110COMNTOOLS") 
    & "..\Ide\MSTEST.EXE", "/Testsettings:""" & rwSettings & """" 
    & " /Testcontainer:""" & rwContainer & """" & " /Resultsfile:""" 
    & rwResults & """")

With the various variables defined previously. I had to use the GetEnvironmentVariable("VS110COMNTOOLS") call because I can't guarantee an install location for Visual Studio and need access to the MSTEST executable. "..\Ide\MSTEST.EXE" is because the environment variable will only get me to the right area and I'll need to have the system navigate to IDE before it finds MSTEST.

I want to clean this up because it's not very elegant or readable, and also because I want to be able to raise events running this process. However, I'm not seeing documentation on how the Process class handles arguments. How can I have the Process object I create handle the multiple arguments (that might have spaces in the name)?

Was it helpful?

Solution

You may try this:

Dim Testsettings As String = "/Testsettings:"""
Dim Testcontainer As String = " /Testcontainer:"""
Dim Resultsfile As String = " /Resultsfile:"""
Dim Quote As String = """"

Dim p As New Process()
p.StartInfo.FileName = Environment.GetEnvironmentVariable("VS110COMNTOOLS") 
                       & "..\Ide\MSTEST.EXE"
p.StartInfo.Arguments = Testsettings & rwSettings & Quote & Testcontainer 
                        & rwContainer & Quote & Resultsfile & rwResults & Quote

p.Start()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top