0

I'm using NSTask to run some bash commands, and have been for quite a while. Lately however, any time I try to do this, normal logging stops in the Xcode console (e.g. from NSLog or Cocoa Lumberjack). The console still shows any output that the bash commands may have, but no further logs appear.

The logs will be appearing as normal, and will stop as soon as I execute:

NSTask *someTask   = [NSTask new];
NSArray *inputArgs = @[@"-l", @"-c", script];

[someTask setLaunchPath:@"/bin/bash"];
[someTask setArguments:inputArgs];

[someTask launch] // This is when the logs stop

This problem seems to have started with the upgrade to Xcode 5.1.1. Any ideas on how to bring back my lovely messages?

Pokey McPokerson
  • 752
  • 6
  • 17
  • 1
    Sounds like a bug in Xcode. A regression. Please file it. As a potential workaround try creating file handles and/or pipes for the task's stdin, stdout, and stderr. – bbum Jun 11 '14 at 15:04
  • Thanks for the suggestion, I piped all the outputs to nul, but unfortunately it still happens. Will report it! – Pokey McPokerson Jun 12 '14 at 06:47

1 Answers1

0

So this seems to be the resurgence of an old bug with Xcode. I found an old answer describing it.

In short I had to change my code to:

NSTask *someTask   = [NSTask new];
NSArray *inputArgs = @[@"-l", @"-c", script];

[someTask setLaunchPath:@"/bin/bash"];
[someTask setArguments:inputArgs];

[someTask setStandardInput:[NSPipe pipe]]; // <-- Added this line.

[someTask launch]
Community
  • 1
  • 1
Pokey McPokerson
  • 752
  • 6
  • 17