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

Linux specific forum
TRS-Eric
User
User
Posts: 16
Joined: Thu Apr 23, 2020 7:42 pm

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

Post 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.
---
BASIC related discord: https://discord.gg/KS4en5y5j4
User avatar
mk-soft
Always Here
Always Here
Posts: 6205
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post by mk-soft »

Works here with Mint Linux and Ubuntu ...

Have you install acpi. (sudo apt install acpi)
Last edited by mk-soft on Thu Apr 04, 2024 10:17 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
TRS-Eric
User
User
Posts: 16
Joined: Thu Apr 23, 2020 7:42 pm

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

Post by TRS-Eric »

Yes, and the command works when I type the command in xterm.
---
BASIC related discord: https://discord.gg/KS4en5y5j4
TRS-Eric
User
User
Posts: 16
Joined: Thu Apr 23, 2020 7:42 pm

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

Post 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
---
BASIC related discord: https://discord.gg/KS4en5y5j4
Post Reply