ReadProgramData() not reading all output for large output
Posted: Sun Jan 21, 2024 8:22 am
Hi
I'm trying to make a Windows shell replication where I open CMD with RunProgram(), then i can type commands in another console and get the output live.
The problem is that with large outputs (for instance running 'dir' command on a folder containing 10.000 files) the output from ReadProgramData() is truncated.
Here is my code :
Where am I wrong ?
Thanks
I'm trying to make a Windows shell replication where I open CMD with RunProgram(), then i can type commands in another console and get the output live.
The problem is that with large outputs (for instance running 'dir' command on a folder containing 10.000 files) the output from ReadProgramData() is truncated.
Here is my code :
Code: Select all
prog = RunProgram("cmd.exe", "", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Write | #PB_Program_Error | #PB_Program_Hide)
OpenConsole("test")
While ProgramRunning(prog)
output$ = ""
cmd$ =Input() ; getting command from user
WriteProgramStringN(prog, cmd$)
Repeat ; if I ommit this waiting loop, the program stucks
Delay(1)
Until AvailableProgramOutput(prog)
While AvailableProgramOutput(prog)
length = AvailableProgramOutput(x)
If length > 0
buffer = AllocateMemory(length)
ReadProgramData(prog, buffer, length)
output$ + PeekS(buffer, length, #PB_UTF8 | #PB_ByteLength)
FreeMemory(buffer)
EndIf
Wend
Debug output$
Wend
Where am I wrong ?
Thanks