Objective c 在沙盒应用程序中运行外部程序
如何制作一个应用程序来显示使用终端中的w命令登录到计算机的所有用户 我制作了测试版应用程序,但它在禁用沙盒的情况下工作[显示用户],但在启用沙盒的情况下不工作[它说没有用户登录]。代码是:Objective c 在沙盒应用程序中运行外部程序,objective-c,macos,Objective C,Macos,如何制作一个应用程序来显示使用终端中的w命令登录到计算机的所有用户 我制作了测试版应用程序,但它在禁用沙盒的情况下工作[显示用户],但在启用沙盒的情况下不工作[它说没有用户登录]。代码是: NSTask *task = [NSTask new]; [task setLaunchPath:@"/usr/bin/w"]; NSPipe *output = [NSPipe pipe]; [task setStandardInput:[NSPipe pipe]]; [task setStandardO
NSTask *task = [NSTask new];
[task setLaunchPath:@"/usr/bin/w"];
NSPipe *output = [NSPipe pipe];
[task setStandardInput:[NSPipe pipe]];
[task setStandardOutput: output];
[task launch];
NSFileHandle * read = [output fileHandleForReading];
NSData * dataRead = [read readDataToEndOfFile];
NSString *result = [[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding];
[TView setString: result];
您尝试运行的实用程序w正在尝试访问沙箱外部的文件。简而言之,当从沙盒应用程序启动时,它将不起作用。您可以尝试使用from the FreeBSD w命令在您的应用程序中实现其功能,看看是否起作用,不知道它是否起作用。但至少你不会有运行外部程序的问题
但是,如果它需要访问非标准区域,则在沙盒应用程序中无法工作。是否有其他方法可以查看可与沙盒一起使用的已登录用户?