Latest 1.1.0
Homepage https://github.com/JohnSundell/ShellOut
License MIT
Platforms osx 10.12

🐚 ShellOut

Welcome to ShellOut, a simple package that enables you to easily “shell out” from a Swift script or command line tool.

Even though you can accomplish most of the tasks you need to do in native Swift code, sometimes you need to invoke the power of the command line from a script or tool – and this is exactly what ShellOut makes so simple.

Usage

Just call shellOut(), and specify what command you want to run, along with any arguments you want to pass:

let output = try shellOut(to: "echo", arguments: ["Hello world"])
print(output) // Hello world

You can also easily run a series of commands at once, optionally at a given path:

try shellOut(to: ["mkdir NewFolder", "echo "Hello again" > NewFolder/File"], at: "~/CurrentFolder")
let output = try shellOut(to: "cat File", at: "~/CurrentFolder/NewFolder")
print(output) // Hello again

In case of an error, ShellOut will automatically read STDERR and format it nicely into a typed Swift error:

do {
    try shellOut(to: "totally-invalid")
} catch {
    let error = error as! ShellOutError
    print(error.message) // Prints STDERR
    print(error.output) // Prints STDOUT
}

Installation

For scripts

  • Install Marathon.
  • Add ShellOut to Marathon using $ marathon add [email protected]:JohnSundell/ShellOut.git.
  • Alternatively, add [email protected]:JohnSundell/ShellOut.git to your Marathonfile.
  • Write your script, then run it using $ marathon run yourScript.swift.

For command line tools

  • Add .Package(url: "https://github.com/JohnSundell/ShellOut.git", majorVersion: 1) to your Package.swift file.
  • Update your packages using $ swift package update.

Help, feedback or suggestions?

  • Open an issue if you need help, if you found a bug, or if you want to discuss a feature request.
  • Open a PR if you want to make some change to ShellOut.
  • Contact @johnsundell on Twitter for discussions, news & announcements about ShellOut & other projects.

Latest podspec

{
    "name": "ShellOut",
    "version": "1.1.0",
    "summary": "Easily run shell commands from a Swift script or command line tool",
    "description": "ShellOut is a simple package that enables you to easily u201cshell outu201d from a Swift script or command line tool.nnEven though you can accomplish most of the tasks you need to do in native Swift code, sometimes you need to invoke the power of the command line from a script or tool - and this is exactly what ShellOut makes so simple.",
    "homepage": "https://github.com/JohnSundell/ShellOut",
    "authors": "John Sundell",
    "social_media_url": "http://twitter.com/JohnSundell",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "osx": "10.12"
    },
    "source": {
        "git": "https://github.com/JohnSundell/ShellOut.git",
        "tag": "1.1.0"
    },
    "source_files": "Sources",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This