# readProcessOutput() - mac

**URL:** <https://forum.juce.com/t/readprocessoutput-mac/8326>\
**Category:** General JUCE discussion\
**Created:** [March 14, 2012, 11:43am UTC](https://forum.juce.com/t/readprocessoutput-mac/8326 "2012-03-14T11:43:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shlomi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shlomi/32/99_2.png) [@Shlomi](https://forum.juce.com/u/Shlomi)\
**Post date:** [March 14, 2012, 11:43am UTC](https://forum.juce.com/t/readprocessoutput-mac/8326/1 "2012-03-14T11:43:38Z")

</div>

I’m getting an empty string when trying to do

```auto
childProcess.start("ps");
String output = childProcess.readAllProcessOutput();
```

It’s also commented in the unit-test

```auto
class ChildProcessTests : public UnitTest
{
public:
    ChildProcessTests() : UnitTest ("ChildProcess") {}

    void runTest()
    {
        beginTest ("Child Processes");

      #if JUCE_WINDOWS || JUCE_MAC || JUCE_LINUX
        ChildProcess p;

       #if JUCE_WINDOWS
        expect (p.start ("tasklist"));
       #else
        expect (p.start ("ls /"));
       #endif

        //String output (p.readAllProcessOutput());
        //expect (output.isNotEmpty());
      #endif
    }
};
```

Maybe it’s because there’s no more output by the time the readProcessOutput gets called?

---

<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:** [March 14, 2012, 11:48am UTC](https://forum.juce.com/t/readprocessoutput-mac/8326/2 "2012-03-14T11:48:05Z")

</div>

Yeah, I had some problems with that, and never managed to figure out what was going wrong. I think it might indeed be that the process has already finished when it gets called.

---

<div class="post-metadata">

**Author:** ![Shlomi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shlomi/32/99_2.png) [@Shlomi](https://forum.juce.com/u/Shlomi)\
**Post date:** [March 14, 2012, 4:00pm UTC](https://forum.juce.com/t/readprocessoutput-mac/8326/3 "2012-03-14T16:00:20Z")

</div>

I ended up using this code, if anyone needs:

```auto
    FILE* pipe = popen(command.toUTF8().getAddress(), "r");
    
    if (!pipe) 
        return String::empty;
    
    char buffer[128];
    String result = String::empty;
    
    while(!feof(pipe)) 
    {
        if(fgets(buffer, 128, pipe) != NULL)
            result += String(buffer);
    }
    pclose(pipe);
    return result;
```
