Thank you so much Gwynne! I had to modify just one thing, then it worked: since we invoke directly hdiutil, I removed "hdiutil" from the args, so now it looks like:
*args = [NSArray arrayWithObjects:@"mount", @"-stdinpass", dmgPath, nil]; The rest was ok. Thanks again. Regards -- Leonardo > Da: Gwynne Raskind <gwy...@darkrainfall.org> > Data: Sun, 14 Mar 2010 15:32:41 -0400 > A: "gMail.com" <mac.iphone....@gmail.com> > Cc: <cocoa-dev@lists.apple.com> > Oggetto: Re: mount dmg disk > > On Mar 14, 2010, at 3:22 PM, gMail.com wrote: >> Hi, >> I can't find a way in Cocoa to mount a dmg disk. >> So I would try to call the shell through a NSTask. >> I succeed on the Terminal when executing this command line: >> >> echo -n password | hdiutil mount /Users/john/Documents/MyDmgDisk.dmg >> >> But when I pass this command line to the NSTask, I fail all the time. >> Furthermore, the app stops to output my NSLog messages to the XCode console. >> Please, what do I miss? >> >> NSString *commandLine = @"echo -n password | hdiutil mount >> /Users/john/Documents/MyDmgDisk.dmg"; >> >> NSArray *args = [NSArray arrayWithObjects:@"-c", commandLine , nil]; >> NSTask *task = [[NSTask alloc] init]; >> [task setLaunchPath:@"/bin/sh"]; >> [task setArguments:args]; >> [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]]; >> [task setStandardError:[NSFileHandle fileHandleWithStandardError]]; >> [task launch]; >> [task waitUntilExit]; >> int result = [task terminationStatus]; >> [task release]; >> >> >> Please note, in case of no password, I simply call >> system("hdiutil mount Users/john/Documents/MyDmgDisk.dmg"); >> and it works well all the time. But even here, I don't know how to deal with >> the password. Any idea? > > > You're relying too heavily on the shell, and you're not passing the necessary > -stdinpass option to hdiutil. Try (written in Mail, no guarantees): > > NSArray *args = [NSArray arrayWithObjects:@"hdiutil", @"mount", > @"-stdinpass", pathToDMG, nil]; > NSTask *task = [[NSTask alloc] init]; > NSPipe *pipe = [NSPipe pipe]; > > [task setLaunchPath:@"/usr/bin/hdiutil"]; > [task setArguments:args]; > [task setStandardInput:pipe]; > [task setStandardOutput:[NSFileHandle fileHandleWithNullDevice]]; > [task setStandardError:[NSFileHandle fileHandleWithStandardError]]; > [task launch]; > [[pipe fileHandleForWriting] writeData:[@"password" > dataUsingEncoding:NSUTF8StringEncoding]]; > [[pipe fileHandleForWriting] closeFile]; > [task waitUntilExit]; > int result = [task terminationStatus]; > [task release]; > > -- Gwynne > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com