QB45 Forums
Party like you didn't do in 1999.

Programming Talk - View Post
Anything related to programming under the sun

Jofers
ADMIN

Posts: 392
I think this is what you're looking for:
Posted by Jofers, on Aug 28th, 2005
Code:
Option Explicit
#include "win/kernel32.bi"
#define BufferSize 1000

Declare Function GetConsoleOutput(ShellCmd As String) As String

Print GetConsoleOutput("fbc x.bas")
Sleep

Function GetConsoleOutput(ConsoleCmd As String) As String
    Dim si As STARTUPINFO
    Dim pi As PROCESS_INFORMATION
    Dim sa As SECURITY_ATTRIBUTES
    Dim hReadPipe As Integer
    Dim hWritePipe As Integer
    Dim sOutput As String
    Dim sBuffer As ZString * BufferSize
    Dim bytesRead As Integer
    Dim result As Integer
   
    sa.nLength = Len(SECURITY_ATTRIBUTES)
    sa.bInheritHandle = 1
   
    If Not CreatePipe(hReadPipe, hWritePipe, ByVal @sa, 0) Then
        Return "Error: Couldn't Create Pipe"
    End If
   
    si.cb = Len(STARTUPINFO)
    si.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
    si.hStdOutput = hWritePipe
    si.hStdError = hWritePipe
    si.wShowWindow = 0
   
    If Not CreateProcess(0, ShellCmd, sa, sa, 1, NORMAL_PRIORITY_CLASS, 0, 0, si, pi) Then
        Return "Error: Couldn't Create Process"
    End If
   
    CloseHandle hWritePipe
   
    Do
        result = ReadFile(hReadPipe, sBuffer, BufferSize, bytesRead, ByVal 0)
        sOutput += Left(sBuffer, bytesRead)
    Loop While result
   
    CloseHandle pi.hProcess
    CloseHandle pi.hThread
    CloseHandle hReadPipe
   
    Return sOutput
End Function


Enjoy.

Back to Programming Talk

Replies:
There are no replies to this message

Post a reply:







All content copyrighted 2004, All rights reserved.