Execute a system command: Difference between revisions

Content added Content deleted
(dc)
(→‎{{header|Objective-C}}: added complete example (because of NSAutoreleasePool I believe it is needed))
Line 276: Line 276:
waitUntilExit];
waitUntilExit];
}
}

Complete usage example:

<!-- {{libheader|Cocoa}} -->

<objc>#import <Cocoa/Cocoa.h>
//works also with
//#import <Foundation/Foundation.h>
//i.e. outside Cocoa (e.g. with GNUstep)

void runSystemCommand(NSString *cmd)
{
[[NSTask launchedTaskWithLaunchPath:@"/bin/sh"
arguments:[NSArray arrayWithObjects:@"-c", cmd, nil]]
waitUntilExit];
}

int main(int argc, const char **argv)
{
NSAutoreleasePool *pool;
pool = [NSAutoreleasePool new];
runSystemCommand(@"ls");
[pool release];
return 0;
}</objc>


Or use the C method above.
Or use the C method above.