How do I modify a shell environment variable in swift?

前端 未结 1 1657
囚心锁ツ
囚心锁ツ 2021-01-05 18:09

How can I access one of the shell env vars when using Process? If I use environment to set them, it will change all of the env vars.



        
相关标签:
1条回答
  • 2021-01-05 18:46

    You might solve it appending on ProcessInfo.processInfo.environment (the inherited environment) your custom path (or whatever you need):

    let task = Process()
    var environment =  ProcessInfo.processInfo.environment
    environment["PATH"] = "/usr/local/bin"
    task.environment = environment
    print(task.environment ?? "")
    
    0 讨论(0)
提交回复
热议问题