I want to read data from a console application that I did not make.
I've tried RunProgram with #PB_Program_Open and #PB_Program_Read flags, but it halts the program and prevents it from continuing execution.
Would anyone happen to have any examples for such a thing? Ideally, I would like to read and write to the program from my own program.
I've tried googling, but I don't think I'm searching for the right terms because everything seems to assume I have the source to both programs.
How can I read stdout from console application using pipes?
How can I read stdout from console application using pipes?
▓▓▓▓▓▒▒▒▒▒░░░░░
-
Lothar Schirm
- User

- Posts: 54
- Joined: Mon Nov 26, 2012 4:57 pm
Re: How can I read stdout from console application using pip
May the description of ReadConsoleData() and WriteConsoleData() in the PureBasic help file be usefull for you?
Re: How can I read stdout from console application using pip
Can you post more code and substitute a generic exe(like robocopy.exe or ipconfig.exe) for your RunProgram() call?
I communicate with external exe's using ReadProgramString() and ReadProgramError(). Haven't used the Console functions, since I keep the RunProgram()'s short and hidden.
I communicate with external exe's using ReadProgramString() and ReadProgramError(). Haven't used the Console functions, since I keep the RunProgram()'s short and hidden.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: How can I read stdout from console application using pip
I remember some issue with a blocking console application as well. As far I remember I've fixed that blocking via adding some further flags (#PB_Program_Write|#PB_Program_Error). I did not need the "write"-flag myself but as far I remember right the other console application required it from my own.
Re: How can I read stdout from console application using pip
My code to launch the program is very simple:skywalk wrote:Can you post more code and substitute a generic exe(like robocopy.exe or ipconfig.exe) for your RunProgram() call?
I communicate with external exe's using ReadProgramString() and ReadProgramError(). Haven't used the Console functions, since I keep the RunProgram()'s short and hidden.
Code: Select all
program = RunProgram("D:/path/server.exe", "", "D:/path/", #PB_Program_Open | #PB_Program_Read)
debug ReadProgramString(program) ; never reachedThis didn't work for me.auser wrote:I remember some issue with a blocking console application as well. As far I remember I've fixed that blocking via adding some further flags (#PB_Program_Write|#PB_Program_Error). I did not need the "write"-flag myself but as far I remember right the other console application required it from my own.
▓▓▓▓▓▒▒▒▒▒░░░░░
- netmaestro
- PureBasic Bullfrog

- Posts: 8453
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: How can I read stdout from console application using pip
There needs to be available program output before you call ReadProgramString. Here's an excerpt from an early version of one of my programs that talks to a chess engine:
Maybe it could be of help to you, dunno. But without checking AvailableProgramOutput() first, ReadProgramString() should be expected to fail most of the time imho. This is the critical sequence:
Code: Select all
engine = RunProgram("Houdini_15a_w32.exe", "", "", #PB_Program_Open | #PB_Program_Read |#PB_Program_Write | #PB_Program_Hide)
WriteProgramStringN(engine, "position startpos")
Delay(1000)
WriteProgramStringN(engine, "go movetime 100")
Repeat
EventID = WaitWindowEvent(1)
If engine
If ProgramRunning(engine)
If AvailableProgramOutput(engine)
e$ = ReadProgramString(engine)
If FindString(e$, "bestmove")
best$ = Mid(e$, 10, 4)
ponder$ = Right(e$, 4)
Move(best$)
EndIf
EndIf
If human_hasmoved
estring$ = "position startpos moves "
ForEach movelist()
estring$+movelist()+" "
Next
WriteProgramStringN(engine, estring$)
Delay(100)
WriteProgramStringN(engine, "go movetime 100")
human_hasmoved=0
humanmove$=""
EndIf
Delay(1)
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Code: Select all
Repeat
EventID = WaitWindowEvent(1)
If engine
If ProgramRunning(engine)
If AvailableProgramOutput(engine)
e$ = ReadProgramString(engine)
BERESHEIT
Re: How can I read stdout from console application using pip
No dice, can't get a return on AvailableProgramOutput()
▓▓▓▓▓▒▒▒▒▒░░░░░

