MidiOutput sendMessageNow not getting to system() call

In my project, I am using Juce for midi signals, and ChucK to create audio.

In one part of my project, the user presses a record button, records for an indefinite amount of time, then stops the recording. I’ve used MidiInputCallback to store each midi message when it is input (as I need them for later calculations), and I also launch some ChucK code with an infinite loop that waits for midi messages to send to its oscillators which are routed to its dac. I use a midi message as a signal to ChucK to break out of its infinite time loop.

When I launch the ChucK program from the terminal, then use sendMessageNow to send the midi message, it breaks successfully. However, when I launch ChucK using system() (e.g. system(“chuck Test.ck &”), the ChucK process does not detect messages from sendMessageNow. It can, however, detect messages from my midi keyboard when launched this way with system().

Any ideas what causes this or what I should try next? I’m not very well versed in C/C++/Unix and what might cause processes launched by system() to act this way.

Here’s some example code that reproduces the problem:

[code]0 => int device;

MidiIn min;
MidiMsg msg;

// try to open MIDI port
if( !min.open( device ) ) me.exit();

while( true )
min => now;
while( min.recv( msg ) ) {
<<< msg.data1 >>>;
if( msg.data1 == 192) {
<<< “Exiting!” >>>;

Inside a Juce program:

midiOut = MidiOutput::openDevice(0);
std::system(“chuck Test.ck &”);

    midiOut->sendMessageNow(MidiMessage::noteOff(1, 44));
    midiOut->sendMessageNow(MidiMessage::programChange(1, 2));[/code]

This produces no output and is stuck in the infinite loop in ChucK. If you replace the call to system() with launching the ChucK process at the command line before running the Juce code, this is the (expected) successful output:

$ chuck Test.ck 128 :(int) 192 :(int) "Exiting!" : (string)