Disabling buffering at RunProgram

Windows specific forum
wb2k
User
User
Posts: 18
Joined: Sun Feb 09, 2014 1:22 am

Disabling buffering at RunProgram

Post by wb2k »

Does anyone know how I can disable buffering at RunProgram?

When I execute gpupdate in an command-window it writes "Updating policy ..." immediately after I started it, but when executed via PureBasic's RunProgram it looks like there is no output until the gpupdate exits:

Code: Select all

handle = RunProgram("gpupdate", "", "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error)
While ProgramRunning(handle)
  Debug "Running ..."
  If AvailableProgramOutput(handle)
    Debug "Output: " + ReadProgramString(handle)
  EndIf
  Delay(500)
Wend
User avatar
Kiffi
Addict
Addict
Posts: 1353
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Disabling buffering at RunProgram

Post by Kiffi »

Some programs write their output to stderr. Try ReadProgramError().
Hygge
wb2k
User
User
Posts: 18
Joined: Sun Feb 09, 2014 1:22 am

Re: Disabling buffering at RunProgram

Post by wb2k »

Kiffi wrote:Some programs write their output to stderr. Try ReadProgramError().
stderr is empty, gpupdate writes to stdout.
The expected output is there at ReadProgramString(), but too late.
User avatar
Ajm
Enthusiast
Enthusiast
Posts: 234
Joined: Fri Apr 25, 2003 9:27 pm
Location: Kent, UK

Re: Disabling buffering at RunProgram

Post by Ajm »

If you try with ReadProgramData does that receive it. Maybe gpupdate is not terminating the string until the end.
Regards

Andy

Image
Registered PB & PureVision User
wb2k
User
User
Posts: 18
Joined: Sun Feb 09, 2014 1:22 am

Re: Disabling buffering at RunProgram

Post by wb2k »

Ajm wrote:If you try with ReadProgramData does that receive it. Maybe gpupdate is not terminating the string until the end.
AvailableProgramOutput() would return true if there is any output (even non-terminating).
In the test-code it is executing the If-branch only near the end of gpupdate, so ReadProgramData won't make any difference.
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: Disabling buffering at RunProgram

Post by Axolotl »

wb2k, if I were you I would give the suggestion made by Ajm a try.

IMHO a closer look at the documentation gives some advice about that.

https://www.purebasic.com/documentation ... utput.html

Result = AvailableProgramOutput(Program)
The number of bytes available to be read from the programs output.

https://www.purebasic.com/documentation ... tring.html

Result$ = ReadProgramString(Program [, Flags])
This function also waits until a full line of output is available. If not line-based or raw output is to be read, ReadProgramData() may be used.

This could be interpreted as waiting for a cr+lf, don't you think?
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Disabling buffering at RunProgram

Post by BarryG »

It's just a cmd box issue, because if you redirect the output like this from a cmd box:

Code: Select all

gpupdate >c:\out.txt
Then the text file is NOT updated until the very end, either - just like PureBasic.

Same if you send the output to the clipboard with "gpupdate | clip" - the clipboard doesn't get updated until the very end, again just like PureBasic.

Conclusion: Nothing you can do, wb2k.
Post Reply