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

      try task.run()

      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 line....is 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

richard

   

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 RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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.