如何将输出控制台(cmd.exe)附加到vb6文本框或panal: 我正在尝试遵循以下步骤:
所以,有人可以帮我吗?
我使用了以下简单代码:
Private Sub Command11_Click(Index As Integer)
Dim sPathUser As String
sPathUser = Environ$("EENV")
Shell sPathUser & "\Xyz.bat"
End Sub
所以,我只想在拨号框或文本编辑器或简单编辑器上显示'Xyz.bat'控制台输出?
答案 0 :(得分:0)
我向您提供了我的工作示例,您使用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