Obj-C Question

cfleck

tired
How can I execute a system command from a obj-c program? I just want to be able to execute something like 'ls -l'. I can't find anything to help me out with this. Ideas?
 
Use the command system("ls -l"). It comes from the stdlib.h file, and for more info look it up in the man pages.
 
system() isn't the recommended way if you're dealing with Cocoa. The best way is to use NSTask:
Code:
NSTask *task = [NSTask launchedTaskWithLaunchPath:@"/bin/ls" arguments:[NSArray arrayWithObject:@"l"]];
 
Ok, almost there. The "system" call is what I need for at least part of it.

I think I need NSTask for some other goodness. Is NSTask the only way I can go about getting the output from said system command?
 
Back
Top