Saving an NSTask Session - Cocoa

I run a simple grep command in my Cocoa application, for example:

NSTask *task;
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/grep"];

NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"foo", @"bar.txt", 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 (@"grep returned:\n%@", string);

[string release];
[task release];

However, I am curious to know how commands entered through the terminal that do not produce output and are not executed promptly if something like Control+ cannot be run from this method C. Something like a launch java -jar server.jarwhere it continues to work until you exit the session. How do I do something like this when the session is not automatically terminated after running the command?

I just need to comment on the part in which he releases NSTask? Any suggestions would be nice!

+3
source share
1 answer

NSTask , :

  • -[NSFileHandle readDataToEndOfFile], . -[NSFileHandle readInBackgroundAndNotify] ;

  • -[NSTask release] , , . , (, , control - d), -terminate -interrupt.

  • -waitUntilExit, .

+7

All Articles