Sender: reads a binary file (first cmdline parameter), uses WriteConsoleData to send it to StdOut
Code: Select all
#READBYTES=4096
OpenConsole()
sFile.s = ProgramParameter(0)
If sFile = ""
PrintN("Usage: sender <filename>"): End
EndIf
hFile = ReadFile(#PB_Any, sFile, #PB_File_SharedRead|#PB_File_SharedWrite)
If hFile = 0
Print("Couldn't read " + sFile)
Else
*buf = AllocateMemory(#READBYTES)
Repeat
nbytes = ReadData(hFile, *buf, #READBYTES)
WriteConsoleData(*buf, nbytes) ;binary version of Print(), nice!
Until Eof(hFile)
CloseFile(hFile)
EndIf
Code: Select all
#READBYTES=4096
OpenConsole()
*buf = AllocateMemory(#READBYTES)
Dumper = RunProgram("sender.exe", "binarytosend.dat", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
If Dumper
While ProgramRunning(Dumper)
If AvailableProgramOutput(Dumper)
nbytes = ReadProgramData(Dumper, *buf, #READBYTES)
;PrintN(PeekS(*buf, nbytes)) ;or whatever buffer processing
EndIf
If Inkey()
If RawKey() = 27: Break: EndIf ;Escape key to allow graceful exit of loop
EndIf
Wend
PrintN("Finished reading binary stream. Exitcode: " + Str(ProgramExitCode(Dumper)))
CloseProgram(Dumper)
EndIf