将输出控制台(cmd.exe)附加到vb6文本框或panal

时间:2013-10-10 05:53:46

标签: vb.net vb6

如何将输出控制台(cmd.exe)附加到vb6文本框或panal: 我正在尝试遵循以下步骤:

  • 点击按钮(将运行批处理文件) 所以,我想在vb6文本框中显示批处理文件的输出,或者我想在VB6面板上显示控制台输出。

所以,有人可以帮我吗?

我使用了以下简单代码:

Private Sub Command11_Click(Index As Integer)
Dim sPathUser As String
sPathUser = Environ$("EENV")
Shell sPathUser & "\Xyz.bat"
End Sub

所以,我只想在拨号框或文本编辑器或简单编辑器上显示'Xyz.bat'控制台输出?

1 个答案:

答案 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