How do I read the standard output from a child process in VB6?

前端 未结 3 453
失恋的感觉
失恋的感觉 2021-01-26 07:44

When creating a process in VB6 (related to this question:), I\'m using the following struct:

Private Type STARTUPINFO
      cb As Long
      lpReserved As String         


        
相关标签:
3条回答
  • 2021-01-26 07:45

    Microsoft gives here an example on how to do it.

    0 讨论(0)
  • 2021-01-26 07:50

    See AttachConsole(ATTACH_PARENT_PROCESS)

    0 讨论(0)
  • 2021-01-26 07:56

    Following up this other question by the OP, I post an alternative method to execute a command and get hold of stdout:

    ' References: "Windows Script Host Shell Object Model" '
    
    Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" ( _
      ByVal dwMilliseconds As Long)
    
    Function ExecuteCommand(cmd As String, ExpectedResult as Long) As String
      Dim shell As New IWshRuntimeLibrary.WshShell
      Dim exec As IWshRuntimeLibrary.WshExec
    
      Set exec = shell.Exec(cmd)
      While exec.Status = 0
         Sleep 100
      Wend
    
      If exec.ExitCode = ExpectedResult Then
        ExecuteCommand = exec.StdOut.ReadAll
      Else
        ExecuteCommand = vbNullString     ' or whatever '
      End
    End Function
    
    0 讨论(0)
提交回复
热议问题