UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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

3      

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

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.