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

问题描述:

当创建在VB6的过程(与this问题:),我使用下面的结构:如何读取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应用程序来读取我的托管过程的输出?

谢谢!

跟进this other question by the 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 
+0

非常好,谢谢! – Pwninstein 2009-02-21 18:04:05

Microsoft这里给出了一个关于如何去做的例子。

+0

优秀的,谢谢!我也发现这个例子(这是类似的):http://www.visualbasic.happycodings.com/Graphics_Games_Programming/code3.html – Pwninstein 2009-02-20 21:35:38

AttachConsole(ATTACH_PARENT_PROCESS)