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

**URL:** <https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555>\
**Category:** General JUCE discussion\
**Created:** [October 11, 2011, 9:55am UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555 "2011-10-11T09:55:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [October 11, 2011, 9:55am UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/1 "2011-10-11T09:55:50Z")

</div>

Windows

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

```auto
  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))
                break;

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

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

                Thread::yield();
            }
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 11, 2011, 10:25am UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/2 "2011-10-11T10:25:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [October 11, 2011, 10:38am UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/3 "2011-10-11T10:38:48Z")

</div>

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… 😃

`/** 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.
    */`

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 11, 2011, 11:42am UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/4 "2011-10-11T11:42:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 22, 2018, 9:37am UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/5 "2018-10-22T09:37:01Z")

</div>

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

I don’t suppose you fancy adding this timeout? 🙂

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [March 2, 2023, 1:03pm UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/6 "2023-03-02T13:03:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 5, 2023, 7:01pm UTC](https://forum.juce.com/t/class-childprocess-activeprocess-read-endless-loop-win32/7555/7 "2023-03-05T19:01:36Z")

</div>

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
