RunProgram problem
Posted: Mon Feb 04, 2013 6:08 pm
I would like to use RunProgram to run a process and collect the output. The problem is that PureBasic seems to hold the output in a buffer and only releases it when the process ends.
These two PureBasic programmes show what I want:
Prog1 is compiled and placed on in the same folder as Progtest.
These work correctly. When I click on the button, the output appears immediately in the debug window.
When I replace prog1 by a programme written in a different language which does exactly the same thing, no output apears in the debug window until the programme ends and then all 10 outputs appear at once.
At first I thought the other language programme must be at fault, but when I run it from the command prompt it behaves correctly. When I type something the output appears immediately.
Can anyone tell me if PureBasic does hold the output in a buffer and, if so, is there anything I can do about it?
Mike
These two PureBasic programmes show what I want:
Code: Select all
;Prog1
If OpenConsole()
For i = 1 To 10
A$ = Input()
A$ = "> " + A$
PrintN(A$)
Next
EndIf
Code: Select all
;Progtest
Quit = #False
program$ = "Prog1.exe"
cmd$ = ""
Prog = RunProgram(program$, cmd$, "" ,#PB_Program_Open |#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide)
If Prog
String$ = "print 37"
EndIf
If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Press")
EndIf
Repeat
Event = WaitWindowEvent(30)
If Event = #PB_Event_CloseWindow
quit = #True
EndIf
If Event = #PB_Event_Gadget
Select EventGadget()
Case 0
R = WriteProgramStringN(Prog, String$)
EndSelect
EndIf
O$ = ""
If ProgramRunning(Prog) And AvailableProgramOutput(Prog)
O$ = O$ + ReadProgramString(Prog)
Debug O$
EndIf
Until Quit = #True
KillProgram(Prog)
CloseProgram(Prog)
Debug "closed"
When I replace prog1 by a programme written in a different language which does exactly the same thing, no output apears in the debug window until the programme ends and then all 10 outputs appear at once.
At first I thought the other language programme must be at fault, but when I run it from the command prompt it behaves correctly. When I type something the output appears immediately.
Can anyone tell me if PureBasic does hold the output in a buffer and, if so, is there anything I can do about it?
Mike