小编Le *_*kin的帖子

AuthorizationExecuteWithPrivileges()作为root错误

我是可可的初学者......

我只想在我的Cocoa App中启动Apache和其他进程.

这是我的代码:

    OSStatus myStatus;
    AuthorizationFlags myFlags = kAuthorizationFlagDefaults;
    AuthorizationRef myAuthorizationRef;
    FILE *pipe = NULL;
    myStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, myFlags, &myAuthorizationRef);
    AuthorizationItem myItems = {kAuthorizationRightExecute, 0, NULL, 0};
    AuthorizationRights myRights = {1, &myItems};
    myFlags = kAuthorizationFlagDefaults | 
    kAuthorizationFlagInteractionAllowed |
    kAuthorizationFlagPreAuthorize |
    kAuthorizationFlagExtendRights;
    myStatus = AuthorizationCopyPrivilegedReference (&myAuthorizationRef,kAuthorizationFlagDefaults);
    myStatus = AuthorizationCopyRights (myAuthorizationRef,&myRights, NULL, myFlags, NULL ); 

    char *tool = "/usr/sbin/apachectl";
    char *args[] = { "start",NULL} ;    

    myStatus = AuthorizationExecuteWithPrivileges(myAuthorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
    char c[100];
    int n=fread(c,1,100,pipe);
    c[n] = '\0';
    NSLog(@"%s\n",c); …
Run Code Online (Sandbox Code Playgroud)

cocoa sudo authorization root nstask

3
推荐指数
1
解决办法
4194
查看次数

NSTextView添加到所选文本的URL链接?

我有一个NSTextView.

我只想NSLinkAttributeNameNSTextView...中的选定文本中添加一个属性(an )

你能帮助我吗 ?

谢谢.

cocoa nstextview

3
推荐指数
1
解决办法
1860
查看次数

标签 统计

cocoa ×2

authorization ×1

nstask ×1

nstextview ×1

root ×1

sudo ×1