|
Writing to STDIN and STDOUT
If you want your application to output results to standard out (stdout), so that other applications can read it, this is how you do it.
Author: mallodog@gis.net
' Constants that will be used in the API functions
Public Const STD_INPUT_HANDLE = -10&
Public Const STD_OUTPUT_HANDLE = -11&
' Declare the needed API functions
Declare Function GetStdHandle Lib "Kernel32" (ByVal nStdHandle As Long) As Long
Declare Function ReadFile Lib "Kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Declare Function WriteFile Lib "Kernel32" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As Any) As Long
Declare Function GetEnvironmentVariable Lib "Kernel32" Alias "GetEnvironmentVariableA" (ByVal bsName As String, ByVal buff As String, ByVal ch As Long) As Long
'======================
' Send output to STDOUT
'======================
'
Sub Send(s As String)
Dim llResult As Long
WriteFile GetStdHandle(STD_OUTPUT_HANDLE), s, Len(s), llResult, ByVal0&
End Sub
'============================
' Get the CGI data from STDIN
'============================
' Data is collected as a single string. We will read it 1024 bytes at a time.
'
Sub GetCGIpostData()
' Read the standard input handle
llStdIn = GetStdHandle(STD_INPUT_HANDLE)
' Get POSTed CGI data from STDIN
Do
lsBuff = String(1024, 0) ' Create a buffer big enough to hold the 1024 bytes
llBytesRead = 1024 ' Tell it we want at least 1024 bytes
If ReadFile(llStdIn, ByVal lsBuff, 1024, llBytesRead, ByVal 0&) Then
' Read the data
' Add the data to our string
postData = postData & Left(lsBuff, llBytesRead)
If llBytesRead < 1024 Then Exit Do
Else
Exit Do
End If
Loop
End Sub
|
||
|
Editor: mallodog@gis.net Last update: 2025-11-03 Copyright 1995-2025 VBI |