从 Swift 脚本或命令行工具轻松执行系统命令。
特性
使用 Process
在 Swift 中运行子进程并不难,但它可能有点繁琐和重复。
System
使这项任务变得非常容易。 如果您熟悉 Ruby 脚本(Rakefile、Fastlane、Danger 等),您会感到宾至如归。
import ProcessRunner
try system(command: "echo hello world") // prints "hello world" to stdout
import ProcessRunner
let output = try system(command: "echo hello world", captureOutput: true).standardOutput
print(output) // prints "hello world"
import ProcessRunner
print(try system(command: "echo hello world").success) // prints "true"
import ProcessRunner
try system(shell: "echo hello cat > cat && cat cat | awk '{print $2}'") // prints "cat" to stdout
将 ProcessRunner
添加到您的 Package.swift
import PackageDescription
let package = Package(
name: "YourPackage",
dependencies: [
.package(url: "git@github.com:eneko/ProcessRunner.git", from: "1.0.0"),
],
targets: [
.target(
name: "YourTarget",
dependencies: ["ProcessRunner"]),
]
)
在 Twitter 上关注或联系我:@eneko。
如果您发现问题,请打开一个 issue。 热烈欢迎 pull requests。
System 在 MIT 许可证下发布。 有关更多信息,请参见LICENSE。