当我尝试为使用 system_profiler 命令检索系统软件和硬件详细信息的应用程序创建帮助程序时,出现以下错误。
来自 XPC 服务的响应:HELLO XPC
来自 XPC 服务的响应:/usr/sbin/system_profiler:/usr/sbin/system_profiler:无法执行二进制文件”
代码如下。
class CommandHelper: NSObject,CommandHelperProtocol {
func upperCaseString(_ string: String, withReply reply: @escaping (String) -> Void) {
let response = string.uppercased()
reply(response)
}
func loadServerURL(_ string: String, withReply reply: @escaping (String) -> Void) {
let pipe = Pipe()
let process = Process()
process.launchPath = "/bin/sh"
process.arguments = ["system_profiler","SPHardwareDataType"]
process.standardOutput = pipe
process.standardError = pipe
let fileHandle = pipe.fileHandleForReading
process.launch()
let response = String(data: fileHandle.readDataToEndOfFile(), encoding: .utf8)
print(response!)
reply(response!)
}
}
当我将 launchPath 设置为 /usr/sbin/system_profiler 时,我得到了空白输出。