开发者

How to get output from Admin Priveleges bash script, called from Cocoa?

开发者 https://www.devze.com 2023-04-11 17:32 出处:网络
I\'m using code below, to launch bash command, with Admin Privileges. I need to be able to store output in Array,after to use it. How can I get output?

I'm using code below, to launch bash command, with Admin Privileges. I need to be able to store output in Array,after to use it. How can I get output?

 char *command1= "/usr/bin/dscl";

char *args1[] = {".","-read","/SharePoints/FolderName","directory_path",nil};

    FILE *pipe = nil;

                            err = AuthorizationCreate(nil,
                              kAuthorizationEmptyEnvironment,
                              kAuthorizationFlagDefaults,
                              &authorizationRef);

        err = AuthorizationExecuteWithPrivileges(authorizationRef,
               开发者_StackOverflow中文版                                command,
                                              kAuthorizationFlagDefaults,
                                              args1,
                                              &pipe);    

Output should be folder -Path of some shared folder. How can I get it, and to store in Array?

P.S. In NSTask is possible to do with NSPipe, but here is File type.

Thanks a lot!


Read from the POSIX file handle (FILE *) that AuthorizationExecuteWithPrivileges returned to you. Don't forget to close it when you're done.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号