kareman / SwiftShell

A Swift framework for shell scripting.
https://kareman.github.io/SwiftShell
MIT License
1.03k stars 87 forks source link

run shell empty output #105

Closed SpectatorNan closed 2 years ago

SpectatorNan commented 2 years ago

i create a mac app. and i run shell which docker. it return stdout is empty string image this code run.

kareman commented 2 years ago

It looks like docker command path is not in the PATH env variable when running the app.

SpectatorNan commented 2 years ago

It looks like docker command path is not in the PATH env variable when running the app.

I don't know if this is because of permission issues or if this app needs to import system environment variables

This app is a CI and code generation tool. Some operational behaviors depend on other tools, such as docker, go, etc.

SpectatorNan commented 2 years ago

The reason is that the path in the APP environment variable is different from the path in the system.

static func startLoadEnv() {
        let userHomePath = EnviromentUtils.userHomeDirPath
        let goOutput = SwiftShell.run(bash: "source \(userHomePath)/.zshrc ; echo $PATH")
        var env = SwiftShell.main.env
        env["PATH"] = "\(goOutput.stdout):/usr/local/bin"
        SwiftShell.main.env = env
    }

This method can be called when the APP starts to solve this problem

kareman commented 2 years ago

Excellent, glad it is working now.