我给你我的工作示例,你使用事件来使用process
类,Async
这样你也可以获得输出数据和错误。
Dim Proceso As New Process
'Register Output async event
AddHandler Proceso.OutputDataReceived, AddressOf CallbackProcesoAsync
'Register error output async event
AddHandler Proceso.ErrorDataReceived, AddressOf ErrorDataReceivedAsync
Dim startInfo As New ProcessStartInfo
startInfo.FileName = execFile
startInfo.Arguments = CmdExeArguments
startInfo.ErrorDialog = False
startInfo.UseShellExecute = False
Private Sub CallbackProcesoAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)
If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then
'Do stuff with your output results
End If
End Sub
Private Sub CallbackProcesoAsync(sender As Object, args As System.Diagnostics.DataReceivedEventArgs)
If Not args.Data Is Nothing AndAlso Not String.IsNullOrEmpty(args.Data) Then
'Do stuff with error output
End If
End Sub