当前位置:  开发笔记 > 后端 > 正文

如何在VB6中读取子进程的标准输出?

如何解决《如何在VB6中读取子进程的标准输出?》经验,为你挑选了1个好方法。

在VB6中创建进程时(与此问题相关:),我使用以下结构:

Private Type STARTUPINFO
      cb As Long
      lpReserved As String
      lpDesktop As String
      lpTitle As String
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Long
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
   End Type

在开始我的流程之前,为了让我的VB6应用程序读取托管进程的输出,STARTUPINFO.hStdOutput需要做些什么?

谢谢!!



1> Tomalak..:

通过OP跟进这个问题,我发布了一个替代方法来执行命令并获取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

推荐阅读
无名有名我无名_593
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有