• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: mount dmg disk
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mount dmg disk


  • Subject: Re: mount dmg disk
  • From: Gwynne Raskind <email@hidden>
  • Date: Sun, 14 Mar 2010 15:32:41 -0400

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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Follow-Ups:
    • Re: mount dmg disk
      • From: "gMail.com" <email@hidden>
References: 
 >mount dmg disk (From: "gMail.com" <email@hidden>)

  • Prev by Date: Re: #include CommonStrings.txt - 'no such file' error
  • Next by Date: Re: Better sorting using threads?
  • Previous by thread: mount dmg disk
  • Next by thread: Re: mount dmg disk
  • Index(es):
    • Date
    • Thread