Mac OS X coding

Wrapping a CLI with Cocoa

March 14, 2007 · No Comments

Using the NSTask method enables one to create a GUI wrapper around a commandline program. For instance, this code snippet derived from CocoaDev shows how to launch the ls utility:

NSTask *task;

task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/ls"];

NSArray *arguments;
arguments = [
NSArray arrayWithObjects: @"-l", @"-a", @"-t",nil];
[task setArguments: arguments];

 

 

 

Categories: NSTask