Page 1 of 1

unable to readprogramstring on debian 12 in LightDM/Openbox for some reason

Posted: Wed Apr 03, 2024 4:07 am
by TRS-Eric
Hello all,

I am having a problem with RunProgram. I am running software but when I try to read the output, it is completely blank, but it is only blank when I'm running it on a stripped down version of Debian 12. If I'm using my full install of Debian 12 with LXQT it reads the program just fine.

The install I'm using is described in the readme of my software:
https://gitlab.com/trs-eric/picotron-laptop-bridge

Specifically, my small version of Debian is running LightDM and Openbox, and xterm is installed but I don't think PB cares about that.

Code: Select all

                  Define batstat.i = RunProgram("acpi", "","", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
                  Define batterystat.s = ""
                  If IsProgram(batstat)
                    While ProgramRunning(batstat)
                      If AvailableProgramOutput(batstat)
                        Define text.s = ReadProgramString(batstat)
                        If ReadProgramString(batstat) <> ""
                          batterystat = batterystat + text + Chr(13)
                        EndIf
                      EndIf
                    Wend
                    batterystat = batterystat + ReadProgramError(batstat)        
                  EndIf
                  
                  logmsg(batterystat,#debug)
                  
                  If Trim(Trim(StringField(batterystat, 2, ",")),"%") <> ""
                    batterylevel = Val(Trim(Trim(StringField(batterystat, 2, ",")),"%"))
                  EndIf
                  

This should return 0 to 100, but instead the entire output is blank, but again, it works fine on the full blown Debian 12 install that's running Purebasic.

I've determined this because I log call outputs this (the second line is blank which should be the output):
2024/04/02 21:39:22|Console command: acpi
2024/04/02 21:39:22|

Expected output:
2024/04/02 21:46:14|Console command: acpi
2024/04/02 21:46:14|Battery 0: Full, 0%, rate information unavailable

Is there some linux library that needs to be installed to read from the console? I checked through the PB requirements and I don't really see anything that's relavent.

Re: unable to readprogramstring on debian 12 in LightDM/Openbox for some reason

Posted: Wed Apr 03, 2024 5:28 pm
by mk-soft
Works here with Mint Linux and Ubuntu ...

Have you install acpi. (sudo apt install acpi)

Re: unable to readprogramstring on debian 12 in LightDM/Openbox for some reason

Posted: Wed Apr 03, 2024 5:34 pm
by TRS-Eric
Yes, and the command works when I type the command in xterm.

Re: unable to readprogramstring on debian 12 in LightDM/Openbox for some reason

Posted: Thu Apr 04, 2024 7:36 pm
by TRS-Eric
I figured out the bug. When reading the program output, you have to keep reading even after the program exits, as data will be queued up. So annoying!

This might be simplified by not reading any output until after it's done running, but I will need to test that. Anyway, here's the final working procedure:

Code: Select all

Procedure.s getstr_RunProgram(filename.s, parameter.s)
  Define prog.i = RunProgram(filename, parameter,"", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
  
  Define output.s = ""
  
  If prog <> 0
    While ProgramRunning(prog)
      If AvailableProgramOutput(prog)
        output + ReadProgramString(prog)
      EndIf
    Wend
    While AvailableProgramOutput(prog)
      output + ReadProgramString(prog)
    Wend
    output + ReadProgramError(prog)
    CloseProgram(prog)             
  EndIf
  
  ProcedureReturn output
EndProcedure