; Executes the PB compiler with the /? option and displays the output
;
Compiler = RunProgram(#PB_Compiler_Home+"compilers/pbcompiler", "-h", "", #PB_Program_Open | #PB_Program_Read)
Output$ = ""
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Output$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))
CloseProgram(Compiler) ; Close the connection to the program
EndIf
MessageRequester("Output", Output$)
What happens if the program spits out output right before the wend? Wouldn't it be missed? Even more, I usually us a while construct within the ProgrammRunning-loop to get the output (unrelated to my question, but maybe better timing).
AvailableProgramOutput() returns the bytes to read.
If you use ReadProgramString() you can still 'lock' the program, because it waits for a CR.
You should use ReadProgramData() and PeekS().
Also you should read stderr, because many programs are writing also some stuff via this way.
I have the same situation/problem when calling the pb compiler with RunProgram().
And in this particular case, it is not because CRLF is being waited for during reading, because the same result is obtained with ReadProgramData().
See also: Command Prompt vs. RunProgram Output
My solution (which probably only works for me) is to use the combination of OpenConsole(), _wsystem(), and CloseConsole().
I admit, it's not pretty, but it's rare.
Just because it worked doesn't mean it works. PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).