A Swift Library to launch, execute, and get the output of, executables and terminal commands/scripts in a simple and quick way.

What's New


  • Fixed a crash occurring thwne the run functions should return nil.

From version 2.1.1

  • Fixed a problem with the playground not compiling properly when the library is used by other projects
  • Fixed Printer class ambiguity
  • Updated supported platforms

From version 2.1.0:

  • Added a Printer class to enable or disable debug prints
  • Updated Tests to use supported methods instead of the deprecated getOut function
  • Added a Demo playground to try the library
  • Updated the README
  • Updated System requirements, now this library will work on any OS X and macOS versions supported by Swift


Swift Library to launch, run and get the output of executables and terminal commands/scripts in a simple and quick way.


  • Manages the usage of Swift's Process Objects, and so allows the library user to: launch, run or just get the standard output/error of a Process execution
  • Provvides comvenint structs for abstraction and ease of usage
  • Allows for class extensions, and extension libraryes to increase the functionality offered (see the Known extensions for this library section for more info)
  • Provvides a protocol for extensions to conform to the basic usage of the main class
  • Debug checks to ensure the library code is used as intended
  • No particular dependecies


Usage is well documented into the source code, so check that out for more info. To prevent having mirrors of this information, this file will be just limited to the following very usefoul example usage:

import Foundation
import Command

//TODO: Remove this warning when I understood what I need to do
#warning("This code needs the app sandbox to be tuned off for the current project! (unless you decide to execute an embedded executable inside your app's bundle)")

//Disable debug printing for the library
Command.Printer.enabled = false

func info() -> String?{
    var out: String?
    //Execution of the command must be in a separated thread, not the main! .background).sync {
        out = "/usr/bin/uname", args: ["-a"])?.outputString() //Executes the uname -a command and returns it's ouput as a string
    return out

print(info() ?? "Error: launch of the \"uname -a\" command failed!")

What apps/programs is this Library intended for?

This library should be used by non-sandboxed swift apps/programs (unless only commands targeted at embedded executables inside the current bundle are run) or embedded helper tools, that needs to run terminal scripts/commands or separated executables from their own.

This code is intended for macOS only since it requires the system library Process type from the Swift API, that is only available on that platform.


  • To let the code to fully work (expecially the and the Command.get... functions ) your app/program might most likely need to not be sandboxed, unless an executable located inside the current bundle is specified, see the documentation inside the source code for more details.
  • All functions from the Command class needs to be run from a non-main thread, except from the Command.start function.

Known extensions for this library

About the project

This code was created as part of my TINU project and it has been separated and made into it's own library to make the main project's source less complex and more focused on it's aim.

Also having this as it's own library allows for code to be updated separately and so various versions of the main TINU app will be able to be compiled all with the latest version of this library.


  • ITzTravelInTime (Pietro Caruso) - Project creator and main developer



Copyright (C) 2021 Pietro Caruso

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


  • Swift Tools 5.3.0
View More Packages from this Author


  • None
Last updated: Thu Nov 10 2022 22:05:55 GMT-0500 (GMT-05:00)