Tentativo di leggere i dati restituiti da un NSTaskprovoca un blocco che non ritorna mai. Ho verificato che il mio script in esecuzione restituisce effettivamente i dati sia a stdout che a stderr. È un semplice script shell a due righe che invia una riga a stdout e l'altra a stderr.
L'output di NSLog dice
Got handle: <NSConcreteFileHandle: 0x10010a800>
E poi si blocca e basta. Questo è il codice che sto usando.
NSPipe *stderr = [NSPipe pipe];
NSPipe *stdout = [NSPipe pipe];
NSTask *task = [[NSTask alloc] init];
task.standardError = stderr;
task.standardOutput = stdout;
task.standardInput = [NSPipe pipe];
task.launchPath = @"/tmp/f";
[task launchPath];
[task waitUntilExit];
NSFileHandle *fh = [stderr fileHandleForReading];
NSLog(@"Got handle: %@", fh);
[fh readDataToEndOfFile];
NSLog(@"Read it");
risposte:
0 per risposta № 1È perché non hai mai avviato il tuo compito. Chiami
[task launchPath];
Ciò restituisce semplicemente il percorso del task come una stringa, in realtà non avvia il task. Tu vuoi
[task launch];