BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

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      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.