Results 1 to 11 of 11

Thread: [RESOLVED] Communicate two executables through the console

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Resolved [RESOLVED] Communicate two executables through the console

    Hello, I am using a code that calls a console executable with command lines, reads its data and tells me when it ends, fragments of the code that I use so that you have an idea

    Code:
    ' Call this sub to execute and capture a console app.
    ' Ex: Call ExecAndCapture("ping localhost", Text1)
    Public Sub ExecAndCapture(ByVal sCommandLine As String, _
                              cTextBox As TextBox, _
                              Optional ByVal sStartInFolder As _
                                  String = vbNullString)
    Const BUFSIZE         As Long = 1024 * 10
    Dim hPipeRead         As Long
    Dim hPipeWrite        As Long
    Dim sa                As SECURITY_ATTRIBUTES
    Dim si                As STARTUPINFO
    Dim pi                As PROCESS_INFORMATION
    Dim baOutput(BUFSIZE) As Byte
    Dim sOutput           As String
    Dim lBytesRead        As Long
        
        With sa
            .nLength = Len(sa)
            .bInheritHandle = 1    ' get inheritable pipe
                ' handles
        End With 'SA
        
        If CreatePipe(hPipeRead, hPipeWrite, sa, 0) = 0 Then
            Exit Sub
        End If
    
        With si
            .cb = Len(si)
            .dwFlags = STARTF_USESHOWWINDOW Or _
                STARTF_USESTDHANDLES
            .wShowWindow = SW_HIDE          ' hide the window
            .hStdOutput = hPipeWrite
            .hStdError = hPipeWrite
        End With 'SI
        
        If CreateProcess(vbNullString, sCommandLine, ByVal 0&, _
            ByVal 0&, 1, 0&, ByVal 0&, sStartInFolder, si, pi) _
            Then
            Call CloseHandle(hPipeWrite)
            Call CloseHandle(pi.hThread)
            hPipeWrite = 0
            Do
                DoEvents
                If ReadFile(hPipeRead, baOutput(0), BUFSIZE, _
                    lBytesRead, ByVal 0&) = 0 Then
                    Exit Do
                End If
                sOutput = Left$(StrConv(baOutput(), vbUnicode), _
                    lBytesRead)
                cTextBox.SelText = sOutput
            Loop
            Call CloseHandle(pi.hProcess)
        End If
        ' To make sure...
        Call CloseHandle(hPipeRead)
        Call CloseHandle(hPipeWrite)
    
    End Sub
    Now, my question is the following, I would like to make another program that makes vb6 that can send that information, that is, write the console and that can be read with the previous code, I want to communicate two executables but only "using this method"


    I tried these two codes but they didn't work, I'm on window x64
    https://www.tek-tips.com/faqs.cfm?fid=5647
    https://docs.microsoft.com/es-ES/tro...i-applications
    Last edited by LeandroA; Mar 28th, 2021 at 06:23 PM.
    leandroascierto.com Visual Basic 6 projects

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width