How to get output from Admin Priveleges bash scrip

2019-03-06 06:11发布

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,
                                               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!

1条回答
霸刀☆藐视天下
2楼-- · 2019-03-06 06:58

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

查看更多
登录 后发表回答