Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Work
GitHub releaseSwift Package Managerlicense

Execute shell command and get output. Simple and robust.

Table of Contents

Installation

Add Work to Package.swift.

dependencies:[.package(url:"https://github.com/flintbox/Work", from:"0.1.0")]

Work

Work is subclass of Operation wrapping Process object.

Example

Synchronous

import Foundation
import Work
// Create shell commands.
letecho1=Work(
command:"echo 1-1; sleep 1; echo 1-2; sleep 1; echo 1-3",
standardOutputHandler:{ output inprint("echo1 says: \(output)")})letecho2=Work(command:"echo 2-1; sleep 1; echo 2-2; sleep 1; echo 2-3")
// Start them synchronously.
echo1.start()
echo2.start()
// Print standard output of echo2.
print(echo2.standardOutput)

Output

echo1 says: 1-1
echo1 says: 1-2
echo1 says: 1-3
2-1
2-2
2-3

Asynchronous

import Foundation
import Work
// Create shell commands.
letecho1=Work(command:"echo 1-1; sleep 1; echo 1-2; sleep 1; echo 1-3")
echo1.standardOutputHandler ={ output inprint("echo1 says: \(output)")}
echo1.completion ={ result inswitch result {case.success(_):print("echo1 success")case.failure(_, _):print("echo1 failure")}}letecho2=Work(
command:"echo 2-1; sleep 1; echo 2-2; sleep 3; echo 2-3",
standardOutputHandler:{ output inprint("echo2 says: \(output)")}, completion:{ result inswitch result {case.success(_):print("echo2 success")case.failure(_, _):print("echo2 failure")}})
// Start them asynchronously.
OperationQueue().addOperations([echo1, echo2], waitUntilFinished:true)

Output

echo2 says: 2-1
echo1 says: 1-1
echo2 says: 2-2
echo1 says: 1-2
echo1 says: 1-3
echo1 success
echo2 says: 2-3
echo2 success

Contribute

If you have good idea or suggestion? Please, don't hesitate to open a pull request or send me an email.

Hope you enjoy building command line tool with Work!

About

Execute shell command and get output. Simple and robust.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages