Hi,
I've heard of a method to use NSTask by specifying /bin/sh as the launch path, "-c" as the first argument, your command as the second argument and nil as the third argument. I have this code that tries to do a simple "ls /Volumes" command:
But it either a) doesnt return an output or b) crashes the app (cant remember which as im not at my computer right now. Any help would be appreciated.
Thanks
I've heard of a method to use NSTask by specifying /bin/sh as the launch path, "-c" as the first argument, your command as the second argument and nil as the third argument. I have this code that tries to do a simple "ls /Volumes" command:
Code:
- (IBAction)runTask:(id)sender {
NSLog(@"starting");
NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/sh"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"-c", "ls /Volumes", nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog (@"got\n%@", string);
}
But it either a) doesnt return an output or b) crashes the app (cant remember which as im not at my computer right now. Any help would be appreciated.
Thanks