Ever wondered how Visual Studio executes a process - such as a compiler - and displays the text it returns in its own window? It's actually really easy - and here's a simple example as to how.
Shared Function GetProcessText(ByVal process As String, ByVal param As String, ByVal workingDir As String) As String
Dim p As Process = New Process
' this is the name of the process we want to execute
p.StartInfo.FileName = process
If Not (workingDir = "") Then
p.StartInfo.WorkingDirectory = workingDir
End If
.StartInfo.Arguments = param
' need to set this to false to redirect output
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
' start the process
p.Start
' read all the output
' here we could just read line by line and display it
' in an output window
Dim output As String = p.StandardOutput.ReadToEnd
' wait for the process to terminate
p.WaitForExit
Return output
End Function
Comments