shell to RunProgram() translation question

Linux specific forum
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

shell to RunProgram() translation question

Post by Wolfram »

Can someone translate this shell command to use it in RunProgram()?

Code: Select all

echo pw | sudo -S man dd
macOS Catalina 10.15.7
vwidmer
Enthusiast
Enthusiast
Posts: 282
Joined: Mon Jan 20, 2014 6:32 pm

Re: shell to RunProgram() translation question

Post by vwidmer »

Can try this

Code: Select all

Procedure.s BashRun(prun.s)
  Program = RunProgram("bash", "-c "+#DQUOTE$+prun.s+#DQUOTE$+"","", #PB_Program_Open|#PB_Program_Read)
  If Program
    While ProgramRunning(Program)
      If AvailableProgramOutput(Program)
        Output$ + ReadProgramString(Program) + Chr(13)
      EndIf
    Wend
    CloseProgram(Program) ; Close the connection to the program
  EndIf
  ProcedureReturn Output$
EndProcedure

OpenConsole()
Result$ = BashRun("echo pw | sudo -S man dd")
PrintN(Result$)
Debug Result$
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
Post Reply