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 in data that is not line-based or text like files that were redirected to the program through a pipe.
The function reads up to 'Size' number of bytes into the specified buffer, which should be reserved before with AllocateMemory.
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.
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)
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.")
Supported OS
All