NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

Continuous update of long shell command execution

Forums > macOS

Good morning

To run a shell command works fine on macOS with Sift 5.6....fine so far...

func callShell(_ command: String) throws -> String {
      let task = Process()
      let pipe = Pipe()

      task.standardOutput = pipe
      task.standardError = pipe
      task.arguments = ["-c", command]
      task.executableURL = URL(fileURLWithPath: "/bin/zsh")
      task.standardInput = nil


      let data = pipe.fileHandleForReading.readDataToEndOfFile()
      let output = String(data: data, encoding: .utf8)!

      return output

But...if I have to execute a shell command that takes a longer time which outputs current state of execution line by there a way to update the output on SwiftUI line by line as well?

Sort of a console log view....or readDataToEndOfLine if it would exist....but then again the function would return at first EOL.

thanks in advance



Ah bugger......

zsh:1: operation not permitted: /opt/homebrew/bin/python3

Seems no way to use external commands under Swift/SwiftUI....back to Xojo then....


Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.