我想在macOS Application中一个接一个地执行两个命令。例如cd ~/Desktop/MyiOSProject
和'fastlane releaseBeta'
我在下面的方法中实现了命令行执行。当我调用波纹管方法command("cd ~/Desktop/MyiOSProject && fastlane releaseBeta")
时它会抛出我的错误
环境:cd~ / Desktop / MyiOSProject && fastlane releaseBeta:没有这样的文件或目录
func command(args: String..., completion: @escaping (Bool,String, Process)->Void) {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
let outPipe = Pipe()
task.standardOutput = outPipe
task.launch()
task.terminationHandler = {process in
let outdata = outPipe.fileHandleForReading.readDataToEndOfFile()
if var string = String(data: outdata, encoding: .utf8) {
string = string.trimmingCharacters(in: .newlines)
if process.terminationStatus == 0 {
completion(true, string, process)
}else {
completion(false, string, process)
}
return
}
completion(false, "Failed to run command", process)
}
}
在Process
实例中,您没有与终端内部相同的环境。 I. e。搜索路径是不同的 - 尽管你使用/usr/bin/env
。我怀疑无法找到fastlane
命令。如果是这样,解决方案很简单:指定它的完整路径,即。即/usr/local/bin/fastlane
。