本文介绍了如何从Admin Priveleges输出bash脚本,从Cocoa调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码,启动bash命令,具有管理员权限。我需要能够将输出存储在Array中,以后使用它。如何获取输出?
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);
输出应为某个共享文件夹的文件夹-Path。
我如何得到它,并存储在Array?
Output should be folder -Path of some shared folder.How can I get it, and to store in Array?
在NSTask是可能与NSPipe,但这里是文件类型。
P.S. In NSTask is possible to do with NSPipe, but here is File type.
非常感谢。
推荐答案
中读取 AuthorizationExecuteWithPrivileges
返回给您的POSIX文件句柄( FILE *
)。完成后不要忘记关闭它。
Read from the POSIX file handle (FILE *
) that AuthorizationExecuteWithPrivileges
returned to you. Don't forget to close it when you're done.
这篇关于如何从Admin Priveleges输出bash脚本,从Cocoa调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!