使用Process
时,如何访问其中一个shell env变量?如果我使用environment
来设置它们,它将改变所有的env vars。
let task = Process()
// How do I modify PATH only instead of setting the whole dictionary
task.environment = ["PATH": "/usr/local/bin"]
答案 0 :(得分:4)
您可以解决它附加在ProcessInfo.processInfo.environment
(继承的环境)您的自定义路径(或您需要的任何内容):
let task = Process()
var environment = ProcessInfo.processInfo.environment
environment["PATH"] = "/usr/local/bin"
task.environment = environment
print(task.environment ?? "")