cfleck tired Sep 8, 2005 #1 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?
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?
Viro Registered Sep 8, 2005 #2 Use the command system("ls -l"). It comes from the stdlib.h file, and for more info look it up in the man pages.
Use the command system("ls -l"). It comes from the stdlib.h file, and for more info look it up in the man pages.
K kainjow Registered Sep 8, 2005 #3 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"]];
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"]];
Viro Registered Sep 8, 2005 #4 Question about NSTask. Is it portable? On systems other than Mac OS X?
K kainjow Registered Sep 8, 2005 #5 No, NSTask is part of the Cocoa API, which exists only on Mac OS X, and systems that have the GNUstep framework installed.
No, NSTask is part of the Cocoa API, which exists only on Mac OS X, and systems that have the GNUstep framework installed.
cfleck tired Sep 9, 2005 #6 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?
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?