It's worth mentioning that this will leak memory on each call, because the string copy isn't freed.
Freeing that data turns out to be an absolute pain though because of how QB64 calls external functions. I tried to come up with a version that doesn't leak:string pipecom_buffer;
const char* pipecom (char* cmd){
FILE* stream;
const int max_buffer = 256;
char buffer[max_buffer];
pipecom_buffer.clear();
stream = popen(cmd, "r");
if (stream) {
while (!feof(stream)) {
if (fgets(buffer, max_buffer, stream) != NULL) {
pipecom_buffer.append(buffer);
}
}
pclose(stream);
}
return pipecom_buffer.c_str();
}
It appears to work, but it relies on QB64's behaviour of (usually) making a copy of string data. There are cases where it doesn't copy (like if you do `LEN(pipecom("foo"))`) because the string is read-only and that's okay, but I can't verify that it'll be fine in all cases.
Anyway, if you noticed your memory usage was steadily increasing over time, try this version instead.