TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.