Problem with ofSystem() [solved]

In my program only the first call to ofSystem() works, every following call does not.
The same thing occurs in an empty project, so my messy code is not causing the problem. :slight_smile:

Any thoughts? I’m on OSX 10.9.3, Xcode 5.1.1 with OF 8.1.

could it depend on what you’re asking ofSystem() to do? maybe you’re starting thread that locks the main application?

Not really, in my program i call a python script but in the empty project a simple ofSystem(“ls”) won’t perform twice.

cout << ofSystem(“ls”); //works, outputs directory contents
cout << ofSystem(“ls”); //fails, outputs \377\377

This happens even when i put a ofSleepMillis(500); command between the two.

I filed this as an issue on github a while ago- Don’t think it’s been fixed in the repo though.

To fix just replace the line fclose inside ofSystem() with pclose (or _pclose on windows). Here’s the entire function-

I also found that the do/while loop included the \377 (EOF) character, so I modified that as well.

That was an easy fix. Thank you, trentbrooks.

Hi, I have the same problem but with OF 0.8.3, I checked in the source code of ofSystem and fclose has been replaced with close but the problem still persists, any ideas?

I just put cout << ofSystem("echo \"hello world\" ") << endl; twice in ofApp::setup

What’s weird is that sometimes it prints out “hello world” once, sometimes twice and sometimes not at all. Every time I get \377 two times.

I’m still having this same issue running ofSystem("ls") getting /337 in console. I’m on OF v8.4 and it’s been changed to pclose. Anyone have any examples of using this function with success? Also, I’m interested in running several terminal commands using this function any example or ideas how to achieve this, maybe something like running a for loop on a string vector inside this function would work? Any help would be appreciated thanks!