Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 16037

Communicate two executables through the console

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

Viewing all articles
Browse latest Browse all 16037

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>