NSTask and event loop...

Thifu

Registered
Hello everybody!

Here is my problem :

- I have coded a small command line program, actually an othello (reversi) game. It works fine in the Terminal.
- I decided to add a graphical frontend, so I used the 'NSTask' class in Cocoa and 'NSPipe's to communicate with it.

BUT I get no output ! (the input works fine).

I created a small "Hello world" project to look for the bug... It seems to be hiding in my input loop.

With that code in the tool's main.c, I get 'Hello world !' in my Cocoa app :
public static int main (void)
{
printf("Helloworld\n");
return 0;
}


... but with the next piece of code, it is waiting for the program to end before the output is sent to stdout (and my Cocoa Pipe) :
public static int main (void)
{
printf("Helloworld\n");

char c = 'a';

while (c != 'q')
{
c = getchar();
if (c == 'a')
printf("Grrrrr.\n");
}

return 0;
}


That is, nothing happens until I type in the 'q' char, which terminates the NSTask, and then I get simultaneously "Hello world" and "Grrr" if I typed 'a' during the loop.

I think it is a buffer problem (something like a 'flush' needed to force the output to get through the pipe), but I can't find it !

Thank you in advance

Thifu
 
Back
Top