ReadFromStdInput – Read from standard input stream

ReadFromStdInput – Read from standard input stream

Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) _    As LongPrivate Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, _    lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, _    lpNumberOfBytesRead As Long, lpOverlapped As Any) As LongPrivate Const STD_INPUT_HANDLE = -10&' read a number of chars from standard input channel'' if NumBytes < 0 then it reads all the bytes' from the standard input'' NOTE: this routine works only in compiled applicationsFunction ReadFromStdInput(Optional ByVal NumBytes As Long = -1) As String    Dim hStdIn As Long    Dim ret As Long    Dim buffer As String    Dim bytesRead As Long        ' get the handle of standard input    hStdIn = GetStdHandle(STD_INPUT_HANDLE)        ' prepare receiving buffer    buffer = Space$(1024)        Do        ' read from standard input        ret = ReadFile(hStdIn, ByVal buffer, Len(buffer), bytesRead, ByVal 0&)            ' deal with errors        If ret = 0 Then            Err.Raise 1001, , "Unable to read from standard input"        End If                ' append to result built so far        ReadFromStdInput = ReadFromStdInput & Left$(buffer, bytesRead)                ' continue to read if there are more chars    Loop Until bytesRead < Len(buffer)        End Function

See also  How to Avoid Money Transfer Scams  

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist