如何在 VB6 中读取子进程的标准输出? [英] How do I read the standard output from a child process in VB6?

查看:27
本文介绍了如何在 VB6 中读取子进程的标准输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 VB6 中创建进程时(与 this question:),我正在使用以下结构:

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

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

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?

谢谢!!

推荐答案

跟进OP 提出的另一个问题,我发布了另一种方法来执行命令并获取标准输出:

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

这篇关于如何在 VB6 中读取子进程的标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆