class ChildProcess::ActiveProcess::read endless Loop (win32)


I having a endless loop when in try to read from a ChildProcess which generates no output

  int read (void* dest, int numNeeded) const
        int total = 0;

        while (ok && numNeeded > 0)
            DWORD available = 0;

            if (! PeekNamedPipe ((HANDLE) readPipe, nullptr, 0, nullptr, &available, nullptr))

            const int numToDo = jmin ((int) available, numNeeded);

            if (available == 0)
              //  if (! isRunning())      !!!!!!!!!!!!! if nothing is available it should always break


Well, the code does exactly what it’s supposed to do - it’s waiting for your process to either generate some output, or to exit.

If you want a non-blocking read function, that’d be a feature request, but the current one is designed to block.

this function is used by ChildProcess::readProcessOutput, which gives the number of bytes back which were read, and i interpret “will attempt to read” as something non-blocking… , which gives 0 back when there is nothing to read…

but anyway we need something non-blocking… :smiley:

/** Attempts to read some output from the child process. This will attempt to read up to the given number of bytes of data from the process. It returns the number of bytes that were actually read. */

Yeah, sorry - that comment wasn’t very clear! The method should probably have a time-out parameter added to it.

Sorry to dig up an old thread, but I have readProcessOutput also blocking indefinitely…

I don’t suppose you fancy adding this timeout? :slight_smile:

Bump a little problem from 5 years ago :slight_smile: Any chance someone could look at this!

I have a better version that uses non blocking reads and can digest tons of messages generated by the child log (try feeding a compiler or cmake as child process, juce will start buffering and the log will stutter) plus also proper environment control for the children.

Of course it has been ignored by the juce team, so i didn’t even try to spend 5 minutes to push an updated version in github