You need to log in to create posts and topics.
Re: NSTask & gzip
1,678 Posts
#1 · November 28, 2010, 3:29 pm
Quote from Forum Archives on November 28, 2010, 3:29 pmPosted by: artlythere <artlythere@...>
I don't know if the below is any clue or help.From reading, says can't gzip a folder (not sure you are doing that) have to .tar it first (using ditto)Another place says avoid using NSTask for zipping, since it is resource intensive, use a method.Some mentioned creating a pipe. I don't know if the below example is any help for whatyou are trying to do.Here's a handy article perhaps.http://www.cocoabuilder.com/archive/cocoa/288631-ok-break-it-down-for-me-question-about-gzip.html
=== cut here ===NSTask *task=[[NSTask alloc] init];NSPipe *opipe=[NSPipe pipe];NSFileHandle *output=[opipe fileHandleForReading];[task setLaunchPath:...];[task setArguments:...];[task setStandardOutput:opipe];[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(gotData:) name:NSFileHandleDataAvailableNotificationobject:output]; // async read[output waitForDataInBackgroundAndNotify];...[task launch];[task waitUntilExit];=== cut here ===rcOn Nov 28, 2010, at 1:46 PM, Bernie wrote:
I wrote:Have used NSTask to execute Terminal commands before but having trouble with gzip. I'm guessing my arguments are not set up correctly. Anyone see what's wrong in this example?< code snip >'ditto' works:'---------------include "Util_FileDirectory.incl"BeginCFunctionvoid ZipFile( CFStringRef inPath ){NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];NSTask *task = [[[NSTask alloc] init] autorelease];[task setLaunchPath:@"/usr/bin/ditto"];NSString *outPath = [(NSString *)inPath stringByAppendingString:@".zip"];[task setArguments:[NSArray arrayWithObjects:@"-c",(NSString *)inPath,outPath,nil]];[task waitUntilExit];[task launch];[pool drain];}EndCtoolbox ZipFile( CFStringRef inPath )dim as FSRef refdim as CFStringRef pathlong if ( files$( _FSRefOpen,,, ref ) )fn FD_FSRefCreatePath( @ref, @path )ZipFile( path )CFRelease( path )end ifRunApplicationEventLoop()'---------------Would still like to know why gzip doesn't work with NSTask (anyone?).Bernie---------------------------------------------------------------------To unsubscribe, e-mail: [email protected]For additional commands, e-mail: [email protected]
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Posted by: artlythere <artlythere@...>
I don't know if the below is any clue or help.
From reading, says can't gzip a folder (not sure you are doing that) have to .tar it first (using ditto)
Another place says avoid using NSTask for zipping, since it is resource intensive, use a method.
Some mentioned creating a pipe. I don't know if the below example is any help for whatyou are trying to do.
Here's a handy article perhaps.
http://www.cocoabuilder.com/archive/cocoa/288631-ok-break-it-down-for-me-question-about-gzip.html
=== cut here ===
NSTask *task=[[NSTask alloc] init];
NSPipe *opipe=[NSPipe pipe];
NSFileHandle *output=[opipe fileHandleForReading];
[task setLaunchPath:...];
[task setArguments:...];
[task setStandardOutput:opipe];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(gotData:) name:NSFileHandleDataAvailableNotification
object:output]; // async read
[output waitForDataInBackgroundAndNotify];
...
[task launch];
[task waitUntilExit];
=== cut here ===
rc
On Nov 28, 2010, at 1:46 PM, Bernie wrote:
I wrote:Have used NSTask to execute Terminal commands before but having trouble with gzip. I'm guessing my arguments are not set up correctly. Anyone see what's wrong in this example?< code snip >'ditto' works:'---------------include "Util_FileDirectory.incl"BeginCFunctionvoid ZipFile( CFStringRef inPath ){NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];NSTask *task = [[[NSTask alloc] init] autorelease];[task setLaunchPath:@"/usr/bin/ditto"];NSString *outPath = [(NSString *)inPath stringByAppendingString:@".zip"];[task setArguments:[NSArray arrayWithObjects:@"-c",(NSString *)inPath,outPath,nil]];[task waitUntilExit];[task launch];[pool drain];}EndCtoolbox ZipFile( CFStringRef inPath )dim as FSRef refdim as CFStringRef pathlong if ( files$( _FSRefOpen,,, ref ) )fn FD_FSRefCreatePath( @ref, @path )ZipFile( path )CFRelease( path )end ifRunApplicationEventLoop()'---------------Would still like to know why gzip doesn't work with NSTask (anyone?).Bernie---------------------------------------------------------------------To unsubscribe, e-mail: [email protected]For additional commands, e-mail: [email protected]
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
Click for thumbs down.0Click for thumbs up.0