NSTaskのsetStandardInput:
、setStandardOutput:
およびsetStandardError:
セレクターをNSPipeインスタンスと組み合わせて使用して、起動されたプログラムと通信できます。
たとえば、タスクの出力を読み取るには、次のようにします。
task = [[NSTask alloc] init];
[task setStandardOutput: [NSPipe pipe]];
[task setStandardError: [task standardOutput]]; // Get standard error output too
[task setLaunchPath: @"/usr/bin/gdb"];
[task launch];
NSFileHandle
次に、タスクの出力を読み取るために使用できるインスタンスを取得できます。
NSFileHandle *readFromMe = [[task standardOutput] fileHandleForReading];
コマンドをgdbに送信するためのパイプを設定するには、次のように追加します。
[task setStandardInput: [NSPipe pipe]];
タスクを起動する前に。次にNSFileHandle
、
NSFileHandle *writeToMe = [[task standardInput] fileHandleForWriting];