Swift Library to launch, run and get the output of executables and terminal commands/scripts in a simple and quick way.
Process
Objects, and so allows the library user to: launch, run or just get the standard output/error of a Process
executionKnown extensions for this library
section for more info)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!
DispatchQueue.global(qos: .background).sync {
out = Command.run(cmd: "/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!")
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.
Command.run
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.Command
class needs to be run from a non-main thread, except from the Command.start
function.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.
Swift Library to launch, run and get the output of executables and terminal commands/scripts in a simple and quick way. Copyright (C) 2021-2022 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
link |
Stars: 1 |
Last commit: 1 year ago |
SwiftPackagesBase
library to replace the array extensions implementation.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics