Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
/ AsyncCommand Public archive

Structured concurrency for external processes

License

Notifications You must be signed in to change notification settings

cbaltzer/AsyncCommand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AsyncCommand

A structured concurrency wrapper for running external processes.

Usage

let homeURL = FileManager.default.homeDirectoryForCurrentUser
let path = homeURL.path + "/Desktop"

let ffmpeg = Command(name: "ffmpeg",
                     command: "/usr/local/bin/ffmpeg",
                     arguments: [
                        "-y",
                        "-i", "\(path)/big_buck_bunny_720.mov",
                        "-c:v", "hevc_videotoolbox",
                        "\(path)/big_buck_bunny_h265.mp4"
                     ],
                    verbose: true)
                    
try await ffmpeg.run()

Error Phrases

Sometimes a script or tool might not actually exit with non-zero in the case of an error. The errorPhrases parameter takes a list of strings which are used to indicate that the command has failed.
The output of the command is searched for these phrases, setting the status to .error if there's a match, regardless of what the command returns.