RunProgram() and #PB_PROGRAM_WRITE problem

Post bugreports for the Windows version here
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

RunProgram() and #PB_PROGRAM_WRITE problem

Post by infratec »

Hi,

with some programs it is not possible to catch stdout and stderr if #PB_PROGRAM_WRITE is also applied.
For example: python

Code: Select all

EnableExplicit

Define Python.i, State.i, Err$, OutLen.i, *Buffer


Python = RunProgram("python.exe", "-u -", GetPathPart(ProgramFilename()), #PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Error|#PB_Program_Ascii)
;Python = RunProgram("python.exe", "-u -", GetPathPart(ProgramFilename()), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Ascii)
If Python
  While ProgramRunning(Python)
    
    OutLen = AvailableProgramOutput(Python)
    If OutLen
      *Buffer = AllocateMemory(OutLen, #PB_Memory_NoClear)
      If *Buffer
        If ReadProgramData(Python, *Buffer, OutLen) = OutLen
          Debug "stdin: " + PeekS(*Buffer, OutLen, #PB_Ascii)
          
          If State = 0
            Debug "quit()"
            WriteProgramStringN(Python, "quit()", #PB_Ascii)
            State + 1
          EndIf
          
        EndIf
        FreeMemory(*Buffer)
      EndIf
    EndIf
    
    Err$ = ReadProgramError(Python, #PB_Ascii)
    If Len(Err$)
      Debug "stderr: " + Err$
    EndIf
    
  Wend
  
  Debug ProgramExitCode(Python)
  
  CloseProgram(Python)
EndIf
If you change the RunProgram() line you can see the stderr output.

PB 5.50 x86 on win10 x64

Btw. small python:
https://www.python.org/ftp/python/3.5.2 ... -win32.zip
unzip it and save the PB code in the same directory.

Bernd
User avatar
the.weavster
Addict
Addict
Posts: 1536
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: RunProgram() and #PB_PROGRAM_WRITE problem

Post by the.weavster »

Bump.

I know this is an old bug report but it would be nice if it could be fixed in PB 6.0
Post Reply