【发布时间】:2010-02-26 17:09:09
【问题描述】:
在 Cocoa 中,我正在尝试实现一个按钮,当用户单击该按钮时,它将捕获系统分析器报告并将其粘贴到桌面上。
代码
NSTask *taskDebug;
NSPipe *pipeDebug;
taskDebug = [[NSTask alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(taskFinished:) name:NSTaskDidTerminateNotification object:taskDebug];
[profilerButton setTitle:@"Please Wait"];
[profilerButton setEnabled:NO];
[taskDebug setLaunchPath: @"/usr/sbin/system_profiler"];
NSArray *args = [NSArray arrayWithObjects:@"-xml",@"-detailLevel",@"full",@">", @"
~/Desktop/Profiler.spx",nil];
[taskDebug setArguments:args];
[taskDebug launch];
但这不会将文件保存到桌面。有 NSArray *args = [NSArray arrayWithObjects:@"-xml",@"-detailLevel",@"full",nil] 工作,它会在控制台窗口中删除整个 sys 分析器输出。
关于为什么这不起作用或如何更好地实现这一点的任何提示?我试图避免使用 shell 脚本或 AppleScript 来获取系统分析器。如果没有任何工作,那将是我的最终选择。 提前致谢。
【问题讨论】: