Post

Replies

Boosts

Views

Activity

Reply to Execute command line tools /usr/bin from a SwiftUI Sandboxed app
Thx, I will try to use the URL.. My code look like this. The task.launchpath = /usr/bin/rsync... Will try to replace as you advice... func executeProcess() async { // Must check valid rsync exists guard SharedReference.shared.norsync == false else { return } // Process let task = Process() // Getting version of rsync task.launchPath = GetfullpathforRsync().rsyncpath task.arguments = arguments // Pipe for reading output from Process let pipe = Pipe() task.standardOutput = pipe task.standardError = pipe let outHandle = pipe.fileHandleForReading outHandle.waitForDataInBackgroundAndNotify() // Combine, subscribe to NSNotification.Name.NSFileHandleDataAvailable NotificationCenter.default.publisher( for: NSNotification.Name.NSFileHandleDataAvailable) .sink { _ in let data = outHandle.availableData if data.count > 0 { if let str = NSString(data: data, encoding: String.Encoding.utf8.rawValue) { self.outputprocess?.addlinefromoutput(str: str as String) } outHandle.waitForDataInBackgroundAndNotify() } }.store(in: &subscriptons) // Combine, subscribe to Process.didTerminateNotification NotificationCenter.default.publisher( for: Process.didTerminateNotification) .debounce(for: .milliseconds(500), scheduler: globalMainQueue) .sink { _ in // Process termination and Log to file self.processtermination(self.outputprocess?.getOutput(), self.config?.hiddenID) _ = Logfile(TrimTwo(self.outputprocess?.getOutput() ?? []).trimmeddata, error: false) // Release Combine subscribers self.subscriptons.removeAll() }.store(in: &subscriptons) SharedReference.shared.process = task do { try task.run() } catch let e { let error = e propogateerror(error: error) } if let launchPath = task.launchPath, let arguments = task.arguments { Logger.process.info("RsyncProcessAsync: \(launchPath, privacy: .public)") Logger.process.info("RsyncProcessAsync: \(arguments.joined(separator: "\n"), privacy: .public)") } }
Feb ’24