Odd: ReadProgramString() running external commands
Posted: Sat Aug 02, 2008 9:54 pm
I'm posting this for (further?) clarification, as it puzzled me.
The correct way to interact with console commands seems to be:
That's also because using the following:
you will never see "done!" - the program will seem to run forever.
This seems to be related to ReadProgramString(), as on the other hand using ReadProgramData() works:
Sum-up: apparently,
- a console program will not end while its output buffer contains data, but
- a console program does not need end its output with a newline.
A program can run forever telling you you have output, you might not be able to necessarily fetch it with ReadProgramString()
Besides, I can't match what I am experiencing with the following from Timo:
and that "will not return immediately" - but not at program end
Pls correct me if I'm wrong / not precise.
The correct way to interact with console commands seems to be:
Code: Select all
p=RunProgram("ls", "-al", ".", #PB_Program_Read|#PB_Program_Open)
While ProgramRunning(p)
Debug ReadProgramString(p)
Wend
Debug "done!"Code: Select all
p=RunProgram("ls", "-al", ".", #PB_Program_Read|#PB_Program_Open)
While ProgramRunning(p)
If AvailableProgramOutput(p)
Debug ReadProgramString(p)
EndIf
Wend
; You won't go past this
Debug "done!"This seems to be related to ReadProgramString(), as on the other hand using ReadProgramData() works:
Code: Select all
s.s=Space(1024)
p=RunProgram("ls", "-al", ".", #PB_Program_Read|#PB_Program_Open)
While ProgramRunning(p)
If AvailableProgramOutput(p)
Debug ReadProgramData(p,@s,Len(s))
EndIf
Wend
; You'll go past this
Debug "done!"- a console program will not end while its output buffer contains data, but
- a console program does not need end its output with a newline.
A program can run forever telling you you have output, you might not be able to necessarily fetch it with ReadProgramString()
Besides, I can't match what I am experiencing with the following from Timo:
unless it means that at program end the function will "return" (instead of waiting) - but not output, [EDIT: no, sorry, that would not be the case for the first example]The ReadProgramString() waits until a newline is found before it returns (or at program end for the last line),
so if the program outputs text but no newline, AvailableProgramOutput() will
return nonzero, but ReadProgramString() will not return immediately.
and that "will not return immediately" - but not at program end
Pls correct me if I'm wrong / not precise.