Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa/run sudo



This works for me ... You need sudo -S to take the password from stdin


// we need a pipe for stdin to pass a password to sudo
NSPipe * stdinPipe = [[NSPipe alloc] init];
// to write to the pipe we need a file handle
NSFileHandle * pipeWrite = [stdinPipe fileHandleForWriting];
// can only write NSData to a file handle
NSData * password = [user_password dataUsingEncoding:NO];
// write the data and close the pipe
[pipeWrite writeData:password];
[pipeWrite closeFile];
// set the pipe to stdin for our script task
[removeMRTask setStandardInput:stdinPipe];
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Cocoa/run sudo (From: Michael Mulligan <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.