peterv
April 26, 2012, 2:21pm
1
Hi,
I use the following code to run a perl script from within my JUCE application
ChildProcess child;
if(child.start(processStr))
{
const String result (child.readAllProcessOutput());
child.waitForProcessToFinish (60 * 1000);
return result;
}
else
{
return "failed to start process";
}
On Linux this works and I get the result String with the output from the perl script. However on Mac the result String is empty.
The process runs fine but the output is missing.
I am running Mac OS 10.7.3 and Xcode 4.3.2.
Thanks,
Peter
Shlomi
April 27, 2012, 7:01am
2
Maybe It’s a timing issue and by the time you call readAllProcessOutput() your perl script had already released its output.
peterv
April 29, 2012, 11:44am
3
Yes, it could be a timing issue. The return String readAllProcessOutput() is always empty on Mac.
I changed the running a process code to
FILE* pipe = popen(processString, "r");
if (!pipe) return "ERROR";
char buffer[128];
String result = "";
while(!feof(pipe)) {
if(fgets(buffer, 128, pipe) != NULL)
result += buffer;
}
pclose(pipe);
return result;
and now I get the process output on both Mac and Linux.
jules
April 30, 2012, 9:35am
4
It probably is some sort of timing issue, but I can’t see where it could be happening…