Created
April 14, 2011 05:11
-
-
Save skahack/918925 to your computer and use it in GitHub Desktop.
exec system command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSString *)runCommand:(NSString *)command { | |
NSTask *task = [[NSTask alloc] init]; | |
NSPipe *pipe = [[NSPipe alloc] init]; | |
[task setLaunchPath: @"/bin/sh"]; | |
[task setArguments: [NSArray arrayWithObjects:@"-c", command, nil]]; | |
[task setStandardOutput: pipe]; | |
[task launch]; | |
NSFileHandle *handle = [pipe fileHandleForReading]; | |
NSData *data = [handle readDataToEndOfFile]; | |
NSString *result = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; | |
[pipe release]; | |
[task release]; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment