Winapi 如何在VB6中读取子进程的标准输出?
在VB6中创建进程(与问题:)时,我使用以下结构:Winapi 如何在VB6中读取子进程的标准输出?,winapi,vb6,stdout,Winapi,Vb6,Stdout,在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 Lo
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.hst输出需要做什么才能让我的VB6应用程序读取托管进程的输出
谢谢 这里给出了一个如何执行的示例。请参见附件控制台(附件父进程)
接下来,我发布了一个替代方法来执行命令并获得标准输出:
' 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
太好了,谢谢!我还发现了这个例子(与之类似):这非常有效!谢谢有没有办法在子进程执行期间隐藏窗口(在本例中是控制台窗口)?恐怕没有。出于某种原因,只有“shell.Run”方法才能隐藏窗口。但是在那里你找不到stdout。如果忽略窗口不是您的选择,那么您又回到了Win32 API调用方法。我想我解决了这个问题:我将把.NET应用程序(子进程)构建为Windows应用程序(而不是控制台应用程序)。这样,就不会显示UI。这是一种方法,您可以这样做::-)您还可以尝试将.NET应用程序公开给COM并直接使用它。