Vb.net 显示Process.Start的输出
我有一个Process.Start命令,我希望看到它的输出,但是新窗口的打开和关闭速度太快,我看不到任何东西。以下是我目前使用的代码:Vb.net 显示Process.Start的输出,vb.net,visual-studio-2012,Vb.net,Visual Studio 2012,我有一个Process.Start命令,我希望看到它的输出,但是新窗口的打开和关闭速度太快,我看不到任何东西。以下是我目前使用的代码: System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("VS110COMNTOOLS") & "..\Ide\MSTEST.EXE", "/Testsettings: """ & rwSettings & "" & " /Testcontainer:
System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("VS110COMNTOOLS") & "..\Ide\MSTEST.EXE", "/Testsettings: """ & rwSettings & "" & " /Testcontainer: """ & rwContainer & "" & " /Resultsfile: """ & rwResults & "")
不幸的是,当我尝试调试它时,如果我允许它运行,它会在窗口中闪烁,但不让我看到错误是什么,或者它是否成功运行。我使用的是VS2012,所以在调试时可能看不到正确的视图。这里有一些代码是从一些逻辑中间提取出来的,因此它不是独立的。您可以使用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()
改为运行cmd.exe。将参数设置为“/c prog.exe args&&pause”或“/k prog.exe args”。如果您只想在屏幕上查看结果,最好选择Hans answer。