Problematic NSTask issue
Problematic NSTask issue
- Subject: Problematic NSTask issue
- From: "Aaron Vegh" <email@hidden>
- Date: Tue, 4 Dec 2007 09:37:10 -0500
Hello all,
My application calls for the ability to zip and unzip a file; research
has indicated that using NSTask to call either zip or ditto from the
command line is the best way to go. My code currently looks something
like this:
NSTask *backupTask = [[NSTask alloc] init];
[backupTask setLaunchPath:@"/usr/bin/zip"];
[backupTask setArguments:
[NSArray arrayWithObjects:@"-r", @"-j", finalFilename, file, nil]];
// Launch it and wait for execution
[backupTask launch];
[backupTask waitUntilExit];
This works just fine! I end up with a zipped file, and it works great.
But then, I want to unzip it. Here's my code:
NSTask *backupTask = [[NSTask alloc] init];
[backupTask setLaunchPath:@"/usr/bin/unzip"];
[backupTask setArguments:
[NSArray arrayWithObjects:file, nil]];
// Launch it and wait for execution
[backupTask launch];
[backupTask waitUntilExit];
And it errors out with a message from unzip saying it can't find the file:
unzip: cannot find or open '/Users/aaron/TestDir/picture.enc',
'/Users/aaron/TestDir/picture.enc'.zip or
'/Users/aaron/TestDir/picture.enc'.ZIP.
'/Users/aaron/TestDir/picture.enc' is the file it should be unzipping.
It's there, I swear! And it's a zipped file; I can change its
extension in the Finder to .zip and double-click it, no problem.
I have also tried using the same unzip command as NSTask would produce
on the command line, in this case:
$ unzip '/Users/aaron/TestDir/picture.enc'
And it works as well! So there's something screwy, it seems, with the
way NSTask is executing this application? Are there other suggestions
for how to troubleshoot this problem?
Thanks in advance!
Aaron.
P.S. I've also tried the above code, exchanging zip for ditto (and
entering the requisite different arguments). Essentially it's the same
problem; ditto can't find the file to unzip either!
--
Aaron Vegh, Principal
Innoveghtive Inc.
P: (647) 477-2690
C: (905) 924-1220
www.innoveghtive.com
www.website-in-a-day.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden