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

发布于 2024-07-14 03:29:38 字数 763 浏览 9 评论 0原文

在 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

在开始我的流程之前,需要对 STARTUPINFO.hStdOutput 进行哪些操作才能让我的 VB6 应用程序读取托管流程的输出?

谢谢!!

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

Before I start my process, what needs to happen to STARTUPINFO.hStdOutput in order for my VB6 app to read the output of my hosted process?

Thanks!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏日浅笑〃 2024-07-21 03:29:38

跟进这个其他问题OP,我发布了一种替代方法来执行命令并获取标准输出:

' 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

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
水水月牙 2024-07-21 03:29:38

Microsoft 在此处提供了有关如何执行此操作的示例。

Microsoft gives here an example on how to do it.

不喜欢何必死缠烂打 2024-07-21 03:29:38

请参阅AttachConsole(ATTACH_PARENT_PROCESS)

See AttachConsole(ATTACH_PARENT_PROCESS)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文