ReadConsoleData()
Syntax
Result = ReadConsoleData(*Buffer, Size)Description
Reads raw input from the console. This function is only supported in non-graphical mode. It can be used to read not line-based data, or text like files redirected to the program through a pipe.
Parameters
*Buffer The memory buffer to which the data should be read. Size The maximum amount of data (in bytes) to be read.
Return value
Returns the number of bytes actually read from the input. If zero is returned, this means that there is no more input to read. (an end of file was received)
Remarks
This function waits until there is some input to read. It will only return without reading data if there was an error or an EOF (End Of File) condition.
Example
; This reads a passed image from the console and displays it in a window
; Compile this to an exe and run it like "myexe < image.bmp"
;
; (set "Executable format" To "Console" in the compiler options!)
; (works only with Bitmaps and icons unless you use an Image Decoder)
;
OpenConsole()
TotalSize = 0
BufferFree = 10000
*Buffer = AllocateMemory(BufferFree)
Repeat
ReadSize = ReadConsoleData(*Buffer+TotalSize, BufferFree) ; read a block of data
TotalSize + ReadSize
BufferFree - ReadSize
If BufferFree < 100 ; resize the buffer if it is not large enough
BufferFree = 10000
*Buffer = ReAllocateMemory(*Buffer, TotalSize+10000)
EndIf
Until ReadSize = 0 ; once 0 is returned, there is nothing else to read
If TotalSize > 0 ; display the image if successful
If CatchImage(0, *Buffer, TotalSize)
If OpenWindow(0, 0, 0, ImageWidth(0), ImageHeight(0), "Image", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(0, 0, 0, ImageWidth(0), ImageHeight(0), ImageID(0))
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
EndIf
EndIf
EndIf
MessageRequester("Error", "Not a valid image.")
See Also
WriteConsoleData(), AllocateMemory()
Supported OS
All