Post

Replies

Boosts

Views

Activity

Returning values from terminal
I'm opening a different thread to a question that was asked about a year ago. I'm trying to get the output of "which" so that I can automatically find programs for the user. I've used the code that was provided in that thread which is:  func launch(tool: URL, arguments: [String], completionHandler: @escaping (Int32, Data) -> Void) throws {         let group = DispatchGroup()         let pipe = Pipe()         var standardOutData = Data()         group.enter()         let proc = Process()         proc.executableURL = tool         proc.arguments = arguments         proc.standardOutput = pipe.fileHandleForWriting         proc.terminationHandler = { _ in             proc.terminationHandler = nil             group.leave()         }         group.enter()         DispatchQueue.global().async {             // Doing long-running synchronous I/O on a global concurrent queue block             // is less than ideal, but I’ve convinced myself that it’s acceptable             // given the target ‘market’ for this code.             let data = pipe.fileHandleForReading.readDataToEndOfFile()             pipe.fileHandleForReading.closeFile()             DispatchQueue.main.async {                 standardOutData = data                 group.leave()             }         }         group.notify(queue: .main) {             completionHandler(proc.terminationStatus, standardOutData)         }         try proc.run()         // We have to close our reference to the write side of the pipe so that the         // termination of the child process triggers EOF on the read side.         pipe.fileHandleForWriting.closeFile()     } it works fine for all of the normal command line routines but not for custom ones such as avr-gcc or any other that is installed via homebrew. I can use "which avr-gcc" in terminal and it shows the path just fine but in my app it returns nothing where as if I search for the path of something like ls in my app it returns it just fine. What could be the cause of this?
3
0
1.1k
Sep ’21