Re: Save Output of NSTask to file
Re: Save Output of NSTask to file
- Subject: Re: Save Output of NSTask to file
- From: "W. W. Gilpin" <email@hidden>
- Date: Tue, 7 Dec 2004 03:17:42 -0600
How can I save the output of NSTask to a file and show it in textview
Presuming the output of the task is not anticipated to be huge,
something like this should get you started:
NSString *theReturnValue = nil;
NSTask *theTask = nil;
NSString *theTempFilePath = [NSTemporaryDirectory()
stringByAppendingPathComponent : @"XXXXXXXXXX"];
char theTP[[theTempFilePath cStringLength]+1];
[theTempFilePath getCString : theTP];
int theFD = mkstemp(theTP);
if (theFD != 0)
{
theTempFilePath = [NSString stringWithCString : theTP];
NSFileHandle *theTempFile = [[NSFileHandle alloc]
initWithFileDescriptor : theFD closeOnDealloc : YES];
theTask = [[NSTask alloc] init];
[theTask setLaunchPath : **YOUR PATH HERE**];
[theTask setStandardOutput : theTempFile];
[theTask launch];
[theTask waitUntilExit];
[theTempFile release];
theReturnValue = [NSString stringWithContentsOfFile : theTempFilePath];
[**YOUR NSTEXTVIEW HERE** setString : theReturnValue];
[[NSFileManager defaultManager] removeFileAtPath : theTempFilePath
handler : nil];
}
HTH,
W. W. Gilpin
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden