5

I've got an NSLog invocation in a method that I know is getting called (I've set a breakpoint). But there's not output in that method, or at all after that method. When the app starts up, my NSLog statements are working fine. I'm wondering if this is some sort of threading issue.

NSLog stops in the taskDidTerminate method, which is a callback from an NSTask:

[[NSNotificationCenter defaultCenter] addObserver:self
                          selector:@selector(taskDidTerminate:)
                          name:NSTaskDidTerminateNotification
                          object:localTask];

Any ideas?

Edit: taskDidTerminate

- (void) taskDidTerminate: (NSNotification *) notification 
{
    NSLog(@"TaskDid Terminate");
    [task.delegate taskCompleted:task];
}
marchaos
  • 3,316
  • 4
  • 26
  • 35

2 Answers2

2

As it turns out, it doesn't look like XCode likes it when you execute a task using /bin/bash -c (task) (commands). I've now changed it to directly execute the task, and now my NSLog() statements are working.

See here for a reference.

marchaos
  • 3,316
  • 4
  • 26
  • 35
2

Adding [task setStandardInput:[NSPipe pipe]]; may bring your logs back as stated on CocoaDev: NSTask.

0xced
  • 25,219
  • 10
  • 103
  • 255
  • 2
    This single line just solved the same problem for me after spending hours on reworking my code and script so that I didn't have to use NSPipe (which I thought was the cause of the "broken" NSLog) to get output from the script, only to discover that NSLog was still broken after my changes. Wish I'd come across this earlier. Thanks – stifin Jul 10 '11 at 12:27