Ok, so I know you can make an NSTask to run command line tools with Objective-C:
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/gdb"];
[task launch];
I'm just wondering if there's a way to communicate with interactive command line tools such a as gdb
. This would involve giving the command inputs based on user interaction (like run
, kill
or quit
with gdb
) and then reacting based on the information it outputs.
You can use NSTask's
setStandardInput:
,setStandardOutput:
andsetStandardError:
selectors in conjunction with NSPipe instances to communicate with the launched program.For example, to read the task's output:
You can then obtain an
NSFileHandle
instance that you can use to read the task's output with:To set up a pipe for sending commands to gdb, you would add
before you launch the task. Then you get the
NSFileHandle
withUse
setStandardInput:
andsetStandardOutput:
methods of NSTaks class.