我有一个Process.Start命令,我希望看到输出,但新窗口打开和关闭太快,我看不到任何东西。这是我到目前为止所使用的代码:
System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("VS110COMNTOOLS") & "..\Ide\MSTEST.EXE", "/Testsettings: """ & rwSettings & "" & " /Testcontainer: """ & rwContainer & "" & " /Resultsfile: """ & rwResults & "")
不幸的是,当我尝试调试它时,如果我允许它运行它会闪烁窗口,但不会让我看到错误是什么,或者它是否正在成功运行。我正在使用VS2012,所以在调试时我可能不会看正确的视图。
答案 0 :(得分:1)
以下是一些逻辑中间的代码,因此它不是独立的。您可以使用ProcessStartInfo()和Process()来获得更多控制权:
Dim start_info As New ProcessStartInfo("sqlcmd", cmd)
start_info.UseShellExecute = False
start_info.CreateNoWindow = True
start_info.RedirectStandardOutput = True
start_info.RedirectStandardError = True
' Make the process and set its start information.
Dim proc As New Process()
proc.StartInfo = start_info
Dim dt As Date = Now()
' Start the process.
proc.Start()
' Attach to stdout and stderr.
Dim std_out As StreamReader = proc.StandardOutput() ' will not continue until process stops
Dim std_err As StreamReader = proc.StandardError()
' Retrive the results.
Dim sOut As String = std_out.ReadToEnd()
Dim sErr As String = std_err.ReadToEnd()