0

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

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

那么,任何人都可以帮助我吗?

我使用了以下简单代码:

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

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

4

1 回答 1

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
于 2013-10-10T06:08:03.267 回答